Skip to content

Commit cb1a03d

Browse files
장아영장아영
authored andcommitted
[#56] ✨ create sign-out proxy server
1 parent adfe93e commit cb1a03d

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

src/app/api/auth/sign-out/route.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { NextResponse } from 'next/server';
2+
3+
export const POST = async (): Promise<NextResponse> => {
4+
try {
5+
const res = NextResponse.json({ success: true, message: '로그아웃 성공' });
6+
7+
res.cookies.set('accessToken', '', {
8+
httpOnly: true,
9+
secure: true,
10+
sameSite: 'strict',
11+
path: '/',
12+
maxAge: 0,
13+
});
14+
15+
res.cookies.set('refreshToken', '', {
16+
httpOnly: true,
17+
secure: true,
18+
sameSite: 'strict',
19+
path: '/',
20+
maxAge: 0,
21+
});
22+
23+
return res;
24+
} catch (error: any) {
25+
console.error('로그아웃 처리 중 오류 발생:', error);
26+
return NextResponse.json(
27+
{ success: false, message: '서버 오류로 로그아웃 실패' },
28+
{ status: 500 }
29+
);
30+
}
31+
};

src/app/page.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,32 @@
33
import { useRouter } from 'next/navigation'
44

55
import axios from 'axios'
6-
6+
import { signOut } from '@/services/auth/auth'
77
import { useAuthStore } from '@/stores/useAuthStore'
88

99
export default function Home(): JSX.Element {
1010
const { logout } = useAuthStore()
11+
1112
const router = useRouter()
1213

1314
const handleLogout = async () => {
1415
try {
15-
await axios.post('/v1/auth/logout', {}, { withCredentials: true })
16-
console.log('서버 로그아웃 성공')
17-
18-
logout()
19-
16+
const response = await fetch(`/api/auth/sign-out`,{
17+
method: 'POST',
18+
headers: {'Content-Type': 'application/json'},
19+
})
20+
if (!response.ok){
21+
const errorResult = await response.json()
22+
console.error('Logout failed')
23+
alert('로그아웃 실패 프록시')
24+
return
25+
}
26+
console.log('Logout successful')
27+
alert('로그아웃 성공 프록시')
2028
router.push('/sign-in')
21-
console.log('로그아웃 성공')
22-
} catch (error) {
23-
console.error('로그아웃 실패:', error)
24-
alert('로그아웃에 실패했습니다.')
29+
} catch(error){
30+
console.error('Logout error', error)
31+
alert('로그아웃 요청 중 오류 발생')
2532
}
2633
}
2734

0 commit comments

Comments
 (0)