File size: 863 Bytes
6aa6081
 
 
 
 
 
 
 
 
 
 
 
 
413032b
6aa6081
 
 
309c40b
6aa6081
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { create } from 'zustand'
import { persist } from 'zustand/middleware'

interface AuthState {
  token: string | null
  user: {
    id: number
    account_id: number
    email: string
    name: string
    lastname: string
    role: string
    plan: string
    organization_name?: string
    self_checkin_enabled: boolean
    checkin_mode: string
    permissions: string[]
    account_purged_at?: string | null
  } | null
  setAuth: (token: string, user: AuthState['user']) => void
  clearAuth: () => void
  isAuthenticated: () => boolean
}

export const useAuthStore = create<AuthState>()(
  persist(
    (set, get) => ({
      token: null,
      user: null,
      setAuth: (token, user) => set({ token, user }),
      clearAuth: () => set({ token: null, user: null }),
      isAuthenticated: () => !!get().token,
    }),
    { name: 'talos-auth' },
  ),
)