auth.client.ts 621 B

1234567891011121314151617181920212223242526
  1. export default defineNuxtPlugin({
  2. name: 'auth',
  3. async setup(nuxtApp) {
  4. const { isAuthenticated, isPlaymate, restoreAuth, refreshAuth, refreshUser, refreshPlaymateInfo } = useAuth()
  5. nuxtApp.hook('app:mounted', () => {
  6. watch(isAuthenticated, (newIsAuthenticated) => {
  7. if (newIsAuthenticated) {
  8. refreshAuth()
  9. refreshUser()
  10. }
  11. }, {
  12. immediate: false,
  13. })
  14. watch(isPlaymate, (newIsPlaymate) => {
  15. if (newIsPlaymate) {
  16. refreshPlaymateInfo()
  17. }
  18. }, {
  19. immediate: false,
  20. })
  21. restoreAuth()
  22. })
  23. },
  24. })