Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/actions/user-check-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
};
Expand Down
16 changes: 3 additions & 13 deletions src/actions/user-signin-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ const GatheringDetailInformation = ({
<div className="flex flex-col gap-3">
<div className="flex flex-col gap-1">
<p className="line-clamp-2 pr-3 text-lg font-semibold">{name}</p>
<p className="text-sm font-medium text-gray-700">{location}</p>
<p className="text-sm font-medium text-gray-700">
{location === "홍대입구" ? "온라인" : location}
</p>
</div>
<DateTimeTag date={dayjs(dateTime)} />
</div>
Expand Down
17 changes: 11 additions & 6 deletions src/app/login/_components/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/utils/cookieToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const setCookieOfToken = async (token: string): Promise<void> => {
value: token,
httpOnly: true,
path: "/",
maxAge: 60 * 60, // 1시간
maxAge: 60 * 60, // 1시간.
secure: process.env.NODE_ENV === "production",
sameSite: "lax",
});
Expand Down