Skip to content

Commit 2c92b4f

Browse files
authored
Merge pull request #508 from meowzip/reese
feat: add global-error.tsx and improve login API token handling
2 parents 9fcda5a + 50165a1 commit 2c92b4f

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

src/app/api/auth/login/route.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@ const extractCookieValue = (
1111
return cookieMatch ? cookieMatch[1] : null;
1212
};
1313

14+
const getCookieDomain = () => {
15+
const isProduction = process.env.NODE_ENV === 'production';
16+
17+
if (!isProduction) {
18+
return 'localhost';
19+
}
20+
21+
return '.meowzip.com';
22+
};
23+
1424
export async function POST(request: NextRequest) {
1525
try {
1626
const body = await request.json();
1727
const { email, password, fcmToken } = body;
18-
1928
const requestOptions = {
2029
method: 'POST',
2130
body: { email, password, fcmToken },
@@ -56,12 +65,13 @@ export async function POST(request: NextRequest) {
5665
);
5766

5867
const isProduction = process.env.NODE_ENV === 'production';
68+
const cookieDomain = getCookieDomain();
5969

6070
const baseCookieOptions = {
6171
secure: isProduction,
6272
path: '/',
6373
sameSite: 'lax' as const,
64-
...(isProduction ? {} : { domain: 'localhost' })
74+
domain: cookieDomain
6575
};
6676

6777
successResponse.cookies.set('Authorization', accessToken, {

src/app/global-error.tsx

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
'use client';
2+
3+
import { useEffect } from 'react';
4+
5+
export default function GlobalError({
6+
error,
7+
reset
8+
}: {
9+
error: Error & { digest?: string };
10+
reset: () => void;
11+
}) {
12+
useEffect(() => {
13+
console.error('Global Error:', error);
14+
}, [error]);
15+
16+
return (
17+
<html>
18+
<body>
19+
<div className="flex min-h-screen items-center justify-center bg-gray-50 px-4">
20+
<div className="w-full max-w-md text-center">
21+
<div className="mb-8">
22+
<div className="mb-4 inline-flex h-20 w-20 items-center justify-center rounded-full bg-red-100">
23+
<svg
24+
className="h-10 w-10 text-red-600"
25+
fill="none"
26+
stroke="currentColor"
27+
viewBox="0 0 24 24"
28+
>
29+
<path
30+
strokeLinecap="round"
31+
strokeLinejoin="round"
32+
strokeWidth={2}
33+
d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z"
34+
/>
35+
</svg>
36+
</div>
37+
<h1 className="mb-2 text-2xl font-bold text-gray-900">
38+
앗, 문제가 발생했어요!
39+
</h1>
40+
<p className="mb-6 text-gray-600">
41+
예상치 못한 오류가 발생했습니다.
42+
<br />
43+
잠시 후 다시 시도해주세요.
44+
</p>
45+
</div>
46+
47+
<div className="space-y-4">
48+
<button
49+
onClick={reset}
50+
className="w-full rounded-lg bg-blue-600 px-4 py-3 font-medium text-white transition-colors hover:bg-blue-700"
51+
>
52+
다시 시도하기
53+
</button>
54+
55+
<button
56+
onClick={() => (window.location.href = '/')}
57+
className="w-full rounded-lg bg-gray-100 px-4 py-3 font-medium text-gray-700 transition-colors hover:bg-gray-200"
58+
>
59+
홈으로 돌아가기
60+
</button>
61+
</div>
62+
63+
{process.env.NODE_ENV === 'development' && (
64+
<details className="mt-6 text-left">
65+
<summary className="cursor-pointer text-sm text-gray-500 hover:text-gray-700">
66+
Developer Info
67+
</summary>
68+
<pre className="mt-2 overflow-auto rounded bg-gray-100 p-3 text-xs text-gray-600">
69+
{error.message}
70+
{error.stack}
71+
</pre>
72+
</details>
73+
)}
74+
</div>
75+
</div>
76+
</body>
77+
</html>
78+
);
79+
}

0 commit comments

Comments
 (0)