24 lines
648 B
TypeScript
24 lines
648 B
TypeScript
|
|
import { create } from 'zustand'
|
||
|
|
import { persist } from 'zustand/middleware'
|
||
|
|
|
||
|
|
interface AuthState {
|
||
|
|
token: string | null
|
||
|
|
memberId: string | null
|
||
|
|
organizationId: string | null
|
||
|
|
setAuth: (token: string, memberId: string, organizationId: string | null) => void
|
||
|
|
logout: () => void
|
||
|
|
}
|
||
|
|
|
||
|
|
export const useAuth = create<AuthState>()(
|
||
|
|
persist(
|
||
|
|
(set) => ({
|
||
|
|
token: null,
|
||
|
|
memberId: null,
|
||
|
|
organizationId: null,
|
||
|
|
setAuth: (token, memberId, organizationId) => set({ token, memberId, organizationId }),
|
||
|
|
logout: () => set({ token: null, memberId: null, organizationId: null }),
|
||
|
|
}),
|
||
|
|
{ name: 'teamup-auth' },
|
||
|
|
),
|
||
|
|
)
|