diff --git a/src/actions/user-check-action.ts b/src/actions/user-check-action.ts index fbadd99..62993cb 100644 --- a/src/actions/user-check-action.ts +++ b/src/actions/user-check-action.ts @@ -21,16 +21,19 @@ const userCheckAction = async (token: string) => { // 유저 정보 받아와서 image null 처리 const resUser: IUser = await response.json(); resUser.image = resUser.image || ""; + return { status: true, user: resUser, error: "", + token: token, }; } catch (err) { return { status: false, user: null, error: `${(err as Error).message}`, + token: null, }; } }; diff --git a/src/actions/user-signin-action.ts b/src/actions/user-signin-action.ts index 01fcb76..757dcee 100644 --- a/src/actions/user-signin-action.ts +++ b/src/actions/user-signin-action.ts @@ -24,32 +24,22 @@ const userSignInAction = async (_: any, formData: FormData) => { // 토큰 받아오기 실패 if (!response.ok) { const errorText = await response.text(); - console.error("API 응답 오류:", errorText); throw new Error(errorText); } - // 토큰을 받아오면 쿠키에 저장 const res = await response.json(); // 유저 정보 확인 - const chkResult = await userCheckAction(res.token); - - // 유저 정보 확인 성공 - if (!chkResult.status) { - throw new Error(chkResult.error); - } + const state = await userCheckAction(res.token); // 성공시 유저 정보 반환 - return { - status: true, - error: "", - user: chkResult.user, - }; + return state; } catch (err) { return { status: false, error: `${(err as Error).message}`, user: null, + token: null, }; } }; diff --git a/src/app/gathering/detail/[id]/_components/GatheringDetailInformation.tsx b/src/app/gathering/detail/[id]/_components/GatheringDetailInformation.tsx index 8a23bc5..0a6743f 100644 --- a/src/app/gathering/detail/[id]/_components/GatheringDetailInformation.tsx +++ b/src/app/gathering/detail/[id]/_components/GatheringDetailInformation.tsx @@ -32,7 +32,9 @@ const GatheringDetailInformation = ({

{name}

-

{location}

+

+ {location === "홍대입구" ? "온라인" : location} +

diff --git a/src/app/login/_components/LoginForm.tsx b/src/app/login/_components/LoginForm.tsx index 0fb659d..ce5f9d5 100644 --- a/src/app/login/_components/LoginForm.tsx +++ b/src/app/login/_components/LoginForm.tsx @@ -18,6 +18,7 @@ import useFavorite from "@/hooks/useFavorite"; import { useModal } from "@/hooks/useModal"; import { LoginFormSchema } from "@/schemas/loginJoinSchema"; import useUserStore from "@/stores/useUserStore"; +import { setCookieOfToken } from "@/utils/cookieToken"; import { IRegisterWithValidation, @@ -68,12 +69,16 @@ const LoginForm = () => { } setIsSubmitting(false); } else if (state && state.status && state.user) { - setUserState(state.user); - - // 로그인 유저의 즐겨찾기 목록 가져오기 - setFavoriteInitValue(state.user?.email); - - router.replace("/"); + setCookieOfToken(state.token) + .then(() => { + setUserState(state.user!); + setFavoriteInitValue(state.user!.email); + router.replace("/"); + }) + .catch(error => { + setAlertMessage("쿠키 설정 오류: " + error.message); + onOpen(); + }); } // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/src/utils/cookieToken.ts b/src/utils/cookieToken.ts index 1fd802a..65b9f79 100644 --- a/src/utils/cookieToken.ts +++ b/src/utils/cookieToken.ts @@ -8,7 +8,7 @@ export const setCookieOfToken = async (token: string): Promise => { value: token, httpOnly: true, path: "/", - maxAge: 60 * 60, // 1시간 + maxAge: 60 * 60, // 1시간. secure: process.env.NODE_ENV === "production", sameSite: "lax", });