Skip to content

Commit da7aaec

Browse files
committed
feat: add cookie clearing logic for failed responses in reissue API
1 parent 40f4ee9 commit da7aaec

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

apps/ticket/src/app/api/reissue/route.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,24 @@ export async function POST(req: Request) {
3535
res.headers.append("Set-Cookie", `${cookie}; Domain=.permitseoul.com`);
3636
}
3737

38+
if (!res.ok) {
39+
clearAuthCookies(res);
40+
}
41+
3842
return res;
3943
}
44+
45+
function clearAuthCookies(res: NextResponse) {
46+
for (const name of ["accessToken", "refreshToken"]) {
47+
res.headers.append(
48+
"Set-Cookie",
49+
`${name}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=None`,
50+
);
51+
52+
// 도메인 쿠키까지 같이 제거
53+
res.headers.append(
54+
"Set-Cookie",
55+
`${name}=; Path=/; Domain=.permitseoul.com; Max-Age=0; HttpOnly; Secure; SameSite=None`,
56+
);
57+
}
58+
}

0 commit comments

Comments
 (0)