-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcallback.tsx
More file actions
41 lines (33 loc) · 1.08 KB
/
callback.tsx
File metadata and controls
41 lines (33 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use client';
import { useEffect } from 'react';
import { useRouter } from 'next/router';
import { exchangeTempToken } from '@/shared/api/auth';
import Loading from '@/pages/loading';
export default function AuthCallbackPage() {
const router = useRouter();
useEffect(() => {
if (!router.isReady) return;
const searchParams = new URLSearchParams(router.asPath.split('?')[1]);
const tempToken = searchParams.get('temp_token');
console.log('tempToken:', tempToken);
if (!tempToken) return;
const handleLogin = async () => {
try {
const res = await exchangeTempToken(tempToken);
console.log('API 응답:', res);
if (res.success) {
console.log('redirect to main 페이지');
router.replace('/main');
} else {
alert(res.message || '로그인에 실패했습니다.');
router.replace('/auth');
}
} catch (error) {
console.error('오류:', error);
router.replace('/auth');
}
};
handleLogin();
}, [router.isReady, router.asPath]);
return <Loading />;
}