24 lines
526 B
TypeScript
24 lines
526 B
TypeScript
import { create } from "zustand";
|
|
import { persist } from "zustand/middleware";
|
|
|
|
|
|
interface AuthStore {
|
|
token: string;
|
|
}
|
|
|
|
export const useAuthStore = create<AuthStore>()(
|
|
persist(
|
|
(set, get) => ({
|
|
token: "",
|
|
}),
|
|
{
|
|
name: "token",
|
|
}
|
|
)
|
|
);
|
|
|
|
export const getAuthToken = () => useAuthStore.getState().token;
|
|
|
|
export const setAuthToken = (token: string) => useAuthStore.setState({ token });
|
|
|
|
export const clearAuthToken = () => useAuthStore.setState({ token: "" }); |