diff --git a/src/app/(auth)/_components/simple-signUpIn.tsx b/src/app/(auth)/_components/simple-signUpIn.tsx index 73c0c812..3e376fd9 100644 --- a/src/app/(auth)/_components/simple-signUpIn.tsx +++ b/src/app/(auth)/_components/simple-signUpIn.tsx @@ -1,12 +1,14 @@ import { Button, Icon } from "@/components"; +import randomStringGenerator from "@/utils/random-string-generator"; import React from "react"; const SimpleSignUpIn = () => { - const client_id = process.env.NEXT_PUBLIC_KAKAO_REST_API_KEY; - const redirect_uri = process.env.NEXT_PUBLIC_REDIRECT_URI; - const kakaoUrl = `https://kauth.kakao.com/oauth/authorize?client_id=${client_id}&redirect_uri=${redirect_uri}&response_type=code`; - const handleKakaoSignin = () => { + const state = randomStringGenerator(10); + const kakao_client_id = process.env.NEXT_PUBLIC_KAKAO_REST_API_KEY; + const kakao_redirect_uri = process.env.NEXT_PUBLIC_KAKAO_REDIRECT_URI; + const kakaoUrl = `https://kauth.kakao.com/oauth/authorize?client_id=${kakao_client_id}&redirect_uri=${kakao_redirect_uri}&response_type=code&state=${state}`; + window.location.href = kakaoUrl; }; @@ -17,18 +19,18 @@ const SimpleSignUpIn = () => { OR
-
- - 간편 로그인하기 + -
+ ); }; diff --git a/src/app/oauth/kakao/redirect.tsx b/src/app/oauth/kakao/redirect.tsx index 1c4fb5e4..2ad611dc 100644 --- a/src/app/oauth/kakao/redirect.tsx +++ b/src/app/oauth/kakao/redirect.tsx @@ -1,20 +1,21 @@ "use client"; import useToast from "@/hooks/use-toast"; -import { deleteCookie, setCookie } from "@/utils/cookie-utils"; +import { deleteCookie } from "@/utils/cookie-utils"; import { setAuthCookies } from "@/utils/setAuthCookies"; import { useRouter, useSearchParams } from "next/navigation"; import { useEffect, useRef } from "react"; import { useQueryClient } from "@tanstack/react-query"; -import randomStringGenerator from "@/utils/random-string-generator"; +import { LoadingSpinner } from "@/components"; +import instance from "@/utils/axios"; const Redirect = () => { const searchParams = useSearchParams(); const router = useRouter(); const queryClient = useQueryClient(); - const redirect_uri = process.env.NEXT_PUBLIC_REDIRECT_URI; + const kakao_redirect_uri = process.env.NEXT_PUBLIC_KAKAO_REDIRECT_URI; const code = searchParams.get("code"); - const state = randomStringGenerator(10); + const state = searchParams.get("state"); const { success: ToastSuccess, error: ToastError } = useToast(); const isProcessing = useRef(false); @@ -28,25 +29,15 @@ const Redirect = () => { deleteCookie("accessToken"); deleteCookie("refreshToken"); - const response = await fetch( - `${process.env.NEXT_PUBLIC_API_URL}/auth/signIn/KAKAO`, - { - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - state: state, - redirectUri: redirect_uri, - token: code, - }), - method: "POST", - } - ); - const data = await response.json(); + const response = await instance.post("auth/signIn/KAKAO", { + state: state, + redirectUri: kakao_redirect_uri, + token: code, + }); - if (!response.ok) throw new Error("로그인 실패"); + const data = response.data; if (data.accessToken && data.refreshToken) { - setCookie("accessToken", data.accessToken); - setCookie("refreshToken", data.refreshToken); await setAuthCookies(data.accessToken, data.refreshToken); } @@ -65,9 +56,13 @@ const Redirect = () => { }; kakaoSignin(); - }, [code, router, redirect_uri, ToastSuccess, ToastError, queryClient]); + }, [code, router, kakao_redirect_uri, ToastSuccess, ToastError, queryClient]); - return
카카오 로그인 중...
; + return ( +
+ +
+ ); }; export default Redirect; diff --git a/src/components/gnb/header/mobile-sidebar.tsx b/src/components/gnb/header/mobile-sidebar.tsx index 1b292dff..a6931577 100644 --- a/src/components/gnb/header/mobile-sidebar.tsx +++ b/src/components/gnb/header/mobile-sidebar.tsx @@ -93,7 +93,7 @@ const MobileSidebar = ({ onClose }: MobileSidebarProps) => { -
+
: "등록하기"} * */ -const LoadingSpinner = ({ ariaLabel = "로딩 중" }: LoadingSpinnerProps) => { +const LoadingSpinner = ({ + ariaLabel = "로딩 중", + className, +}: LoadingSpinnerProps) => { return ( ); diff --git a/src/utils/axios.ts b/src/utils/axios.ts index 18f1a1f5..dc08cfc4 100644 --- a/src/utils/axios.ts +++ b/src/utils/axios.ts @@ -54,7 +54,13 @@ instance.interceptors.request.use( const url = config.url ?? ""; const method = config.method?.toLocaleLowerCase(); - const noTokenURls = ["/", "/signin", "/signup", "/auth/refresh-token"]; + const noTokenURls = [ + "/", + "/signin", + "/signup", + "/auth/refresh-token", + "/auth/signIn/KAKAO", + ]; if (noTokenURls.includes(url)) { return config; } diff --git a/src/utils/cookie-utils.ts b/src/utils/cookie-utils.ts index a5b01cbe..c06237a4 100644 --- a/src/utils/cookie-utils.ts +++ b/src/utils/cookie-utils.ts @@ -18,13 +18,3 @@ export const deleteCookie = (cookieName: string) => { document.cookie = `${cookieName}=; path=/; max-age=0; ${secureFlag}`; document.cookie = `${cookieName}=; max-age=0; ${secureFlag}`; }; - -export const setCookie = (name: string, value: string) => { - const secureFlag = process.env.NODE_ENV === "production" ? "secure" : ""; - let cookieString = `${name}=${value}; path=/`; - - if (process.env.NODE_ENV === "production") { - cookieString += `; ${secureFlag}`; - } - document.cookie = cookieString; -}; diff --git a/tailwind.config.ts b/tailwind.config.ts index fdc84ec4..028de632 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -48,6 +48,7 @@ const config: Config = { yellow: "#EAB308", cyan: "#06B6D4", purple: "#A855F7", + kakao: "#F5E14B", }, screens: { mobile: "375px",