| 1234567891011121314151617181920212223242526272829303132 |
- 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) => {
- console.log('newIsAuthenticated', newIsAuthenticated)
- if (newIsAuthenticated) {
- await refreshAuth()
- await refreshUser()
- await firstOrderDiscountStore.fetchChance()
- }
- else {
- firstOrderDiscountStore.clear()
- }
- }, {
- immediate: true,
- })
- watch(isPlaymate, (newIsPlaymate) => {
- if (newIsPlaymate) {
- refreshPlaymateInfo()
- }
- }, {
- immediate: false,
- })
- })
- },
- })
|