31 lines
666 B
TypeScript
31 lines
666 B
TypeScript
import { create } from 'zustand';
|
|
import { persist } from 'zustand/middleware';
|
|
import type { AuthState, AdminUser } from '../types/admin';
|
|
|
|
export const useAdminAuthStore = create<AuthState>()(
|
|
persist(
|
|
(set) => ({
|
|
accessToken: null,
|
|
adminUser: null,
|
|
isAuthenticated: false,
|
|
|
|
setAuth: (accessToken: string, adminUser: AdminUser) =>
|
|
set({
|
|
accessToken,
|
|
adminUser,
|
|
isAuthenticated: true,
|
|
}),
|
|
|
|
clearAuth: () =>
|
|
set({
|
|
accessToken: null,
|
|
adminUser: null,
|
|
isAuthenticated: false,
|
|
}),
|
|
}),
|
|
{
|
|
name: 'canina_admin_auth',
|
|
}
|
|
)
|
|
);
|