summaryrefslogtreecommitdiff
path: root/app/api/auth/util.ts
diff options
context:
space:
mode:
Diffstat (limited to 'app/api/auth/util.ts')
-rw-r--r--app/api/auth/util.ts52
1 files changed, 52 insertions, 0 deletions
diff --git a/app/api/auth/util.ts b/app/api/auth/util.ts
new file mode 100644
index 00000000..9163c1c5
--- /dev/null
+++ b/app/api/auth/util.ts
@@ -0,0 +1,52 @@
+import { signOut } from 'next-auth/react'
+
+export async function completeLogout() {
+ // 1. NextAuth 로그아웃
+ await signOut({ redirect: false })
+
+ // 2. 모든 NextAuth 관련 쿠키 제거
+ const cookies = [
+ 'next-auth.session-token',
+ '__Secure-next-auth.session-token',
+ 'next-auth.csrf-token',
+ '__Host-next-auth.csrf-token',
+ 'next-auth.callback-url',
+ '__Secure-next-auth.callback-url'
+ ]
+
+ cookies.forEach(cookieName => {
+ document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`
+ document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; secure`
+ document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=${window.location.hostname}`
+ })
+
+ // 3. 로컬 스토리지와 세션 스토리지 클리어
+ localStorage.clear()
+ sessionStorage.clear()
+
+ // 4. 강제 페이지 리로드로 모든 캐시 제거
+ window.location.href = '/ko/evcp'
+}
+
+// 사용자 도메인 변경 후 호출할 함수
+export async function refreshUserSession() {
+ try {
+ const response = await fetch('/api/auth/refresh-user', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ })
+
+ if (response.ok) {
+ // 성공하면 페이지 리로드
+ window.location.reload()
+ } else {
+ // 실패하면 완전 로그아웃
+ await completeLogout()
+ }
+ } catch (error) {
+ console.error('Failed to refresh session:', error)
+ await completeLogout()
+ }
+} \ No newline at end of file