import { useAuthStore } from '~/stores/auth' import { useDetailStore } from '~/stores/detail' import { useVendorsStore } from '~/stores/vendors' export const useLogout = () => { const authStore = useAuthStore() const vendorsStore = useVendorsStore() const detailStore = useDetailStore() 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' case 'BRAND': return 'brand' default: // 3. 기본값은 인플루언서 return 'influence' } } const logout = async () => { try { // 현재 로그인 타입 저장 (로그아웃 전에 미리 저장) const loginType = getLoginType() // auth store 초기화 authStore.setLogout() // vendors store 초기화 vendorsStore.reset() // detail store 초기화 detailStore.reset() // localStorage 정리 localStorage.removeItem('authStore') localStorage.removeItem('tempAccess') // 성공 메시지 표시 $toast.success('로그아웃되었습니다.') // 로그인 타입에 따라 적절한 페이지로 리다이렉트 await navigateTo({ path: '/', query: { type: loginType } }, { replace: true }) } catch (error) { console.error('로그아웃 중 오류 발생:', error) // 오류가 발생해도 로컬 상태는 정리 const loginType = getLoginType() authStore.setLogout() vendorsStore.reset() detailStore.reset() localStorage.clear() await navigateTo({ path: '/', query: { type: loginType } }, { replace: true }) } } return { logout } }