Просмотр исходного кода

feat: update auth store and route guard

Mohammad Mahdi Salimi 1 месяц назад
Родитель
Сommit
20ed1bc42d
2 измененных файлов с 3 добавлено и 6 удалено
  1. 1 5
      src/routes/_authenticated/route.tsx
  2. 2 1
      src/stores/auth-store.ts

+ 1 - 5
src/routes/_authenticated/route.tsx

@@ -20,10 +20,6 @@ export const Route = createFileRoute('/_authenticated')({
 
     const authState = useAuthStore.getState()
 
-    const persisted = localStorage.getItem('auth-storage')
-
-    const hasPersistedToken = persisted && JSON.parse(persisted)?.state?.token
-
     const {
       token,
       isAuthenticated,
@@ -33,7 +29,7 @@ export const Route = createFileRoute('/_authenticated')({
       setProfileFetched,
     } = authState
 
-    if (!token || !isAuthenticated || !hasPersistedToken) {
+    if (!token || !isAuthenticated) {
       logout()
 
       throw redirect({

+ 2 - 1
src/stores/auth-store.ts

@@ -1,3 +1,4 @@
+import { authService } from '@/services/auth.service'
 import { type AdminUser } from '@/types/auth.types'
 import { create } from 'zustand'
 import { persist } from 'zustand/middleware'
@@ -57,7 +58,7 @@ export const useAuthStore = create<AuthState>()(
 
       logout: async () => {
         try {
-          // optional api logout
+          await authService.logout()
         } finally {
           set({
             user: null,