|
@@ -1,31 +1,45 @@
|
|
|
import { useAuthStore } from '~/stores/auth'
|
|
import { useAuthStore } from '~/stores/auth'
|
|
|
import { useVendorsStore } from '~/stores/vendors'
|
|
import { useVendorsStore } from '~/stores/vendors'
|
|
|
import { useDetailStore } from '~/stores/detail'
|
|
import { useDetailStore } from '~/stores/detail'
|
|
|
-import { useRouter } from 'vue-router'
|
|
|
|
|
|
|
|
|
|
export const useLogout = () => {
|
|
export const useLogout = () => {
|
|
|
const authStore = useAuthStore()
|
|
const authStore = useAuthStore()
|
|
|
const vendorsStore = useVendorsStore()
|
|
const vendorsStore = useVendorsStore()
|
|
|
const detailStore = useDetailStore()
|
|
const detailStore = useDetailStore()
|
|
|
- const router = useRouter()
|
|
|
|
|
const { $toast } = useNuxtApp()
|
|
const { $toast } = useNuxtApp()
|
|
|
|
|
|
|
|
|
|
+ const getLoginType = () => {
|
|
|
|
|
+ // 1. snsTempData에서 먼저 확인
|
|
|
|
|
+ if (authStore.auth.snsTempData?.logintype) {
|
|
|
|
|
+ return authStore.auth.snsTempData.logintype
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. memberType 기반으로 판단
|
|
|
|
|
+ const memberType = authStore.auth.memberType?.toUpperCase()
|
|
|
|
|
+ switch (memberType) {
|
|
|
|
|
+ case 'VENDOR':
|
|
|
|
|
+ return 'vendor'
|
|
|
|
|
+ case 'INFLUENCER':
|
|
|
|
|
+ return 'influence'
|
|
|
|
|
+ default:
|
|
|
|
|
+ // 3. 마지막으로 companyId 존재 여부로 판단
|
|
|
|
|
+ return authStore.auth.companyId ? 'vendor' : 'influence'
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const logout = async () => {
|
|
const logout = async () => {
|
|
|
try {
|
|
try {
|
|
|
// 현재 로그인 타입 저장 (로그아웃 전에 미리 저장)
|
|
// 현재 로그인 타입 저장 (로그아웃 전에 미리 저장)
|
|
|
- const loginType = authStore.auth.snsTempData?.logintype || 'vendor' // 기본값은 vendor
|
|
|
|
|
-
|
|
|
|
|
- // API 호출로 서버 세션 종료 (선택적)
|
|
|
|
|
- await useAxios().post('/api/auth/logout')
|
|
|
|
|
|
|
+ const loginType = getLoginType()
|
|
|
|
|
|
|
|
// auth store 초기화
|
|
// auth store 초기화
|
|
|
authStore.setLogout()
|
|
authStore.setLogout()
|
|
|
|
|
|
|
|
// vendors store 초기화
|
|
// vendors store 초기화
|
|
|
- vendorsStore.$reset()
|
|
|
|
|
|
|
+ vendorsStore.reset()
|
|
|
|
|
|
|
|
// detail store 초기화
|
|
// detail store 초기화
|
|
|
- detailStore.$reset()
|
|
|
|
|
|
|
+ detailStore.reset()
|
|
|
|
|
|
|
|
// localStorage 정리
|
|
// localStorage 정리
|
|
|
localStorage.removeItem('authStore')
|
|
localStorage.removeItem('authStore')
|
|
@@ -35,16 +49,22 @@ export const useLogout = () => {
|
|
|
$toast.success('로그아웃되었습니다.')
|
|
$toast.success('로그아웃되었습니다.')
|
|
|
|
|
|
|
|
// 로그인 타입에 따라 적절한 페이지로 리다이렉트
|
|
// 로그인 타입에 따라 적절한 페이지로 리다이렉트
|
|
|
- router.push(`/?type=${loginType}`)
|
|
|
|
|
|
|
+ await navigateTo({
|
|
|
|
|
+ path: '/',
|
|
|
|
|
+ query: { type: loginType }
|
|
|
|
|
+ }, { replace: true })
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error('로그아웃 중 오류 발생:', error)
|
|
console.error('로그아웃 중 오류 발생:', error)
|
|
|
// 오류가 발생해도 로컬 상태는 정리
|
|
// 오류가 발생해도 로컬 상태는 정리
|
|
|
- const loginType = authStore.auth.snsTempData?.logintype || 'vendor'
|
|
|
|
|
|
|
+ const loginType = getLoginType()
|
|
|
authStore.setLogout()
|
|
authStore.setLogout()
|
|
|
- vendorsStore.$reset()
|
|
|
|
|
- detailStore.$reset()
|
|
|
|
|
|
|
+ vendorsStore.reset()
|
|
|
|
|
+ detailStore.reset()
|
|
|
localStorage.clear()
|
|
localStorage.clear()
|
|
|
- router.push(`/?type=${loginType}`)
|
|
|
|
|
|
|
+ await navigateTo({
|
|
|
|
|
+ path: '/',
|
|
|
|
|
+ query: { type: loginType }
|
|
|
|
|
+ }, { replace: true })
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|