middleware
This commit is contained in:
@@ -66,14 +66,20 @@ export default function LoginPage() {
|
||||
const token = data.token || data.accessToken || data.access_token;
|
||||
if (token) {
|
||||
localStorage.setItem('token', token);
|
||||
// 쿠키에도 토큰 저장 (middleware에서 사용)
|
||||
document.cookie = `token=${token}; path=/; max-age=${30 * 24 * 60 * 60}; SameSite=Lax`;
|
||||
console.log("토큰 저장 완료");
|
||||
} else {
|
||||
console.warn("토큰이 응답에 없습니다. 응답 데이터:", data);
|
||||
// 토큰이 없어도 로그인은 성공했으므로 진행
|
||||
}
|
||||
|
||||
// 리다이렉트 경로 확인
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
const redirectPath = searchParams.get('redirect') || '/';
|
||||
|
||||
// 메인 페이지로 이동
|
||||
router.push('/');
|
||||
router.push(redirectPath);
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : "네트워크 오류가 발생했습니다.";
|
||||
console.error("로그인 오류:", errorMessage);
|
||||
|
||||
Reference in New Issue
Block a user