middleware

This commit is contained in:
2025-11-25 00:03:05 +09:00
parent 12413795f4
commit e74061057d
2 changed files with 64 additions and 1 deletions

View File

@@ -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);