export default defineNuxtPlugin({ name: 'auth', async setup(nuxtApp) { const { isAuthenticated, isPlaymate, restoreAuth, refreshAuth, refreshUser, refreshPlaymateInfo } = useAuth() const firstOrderDiscountStore = useFirstOrderDiscountStore() nuxtApp.hook('app:mounted', () => { restoreAuth() watch(isAuthenticated, async (newIsAuthenticated) => { if (newIsAuthenticated) { await refreshAuth() await refreshUser() await firstOrderDiscountStore.fetchChance() } else { firstOrderDiscountStore.clear() } }, { immediate: true, }) watch(isPlaymate, (newIsPlaymate) => { if (newIsPlaymate) { refreshPlaymateInfo() } }, { immediate: false, }) }) }, })