turkmentv_front/store/useLotteryAuth.ts

41 lines
946 B
TypeScript
Raw Permalink Normal View History

2024-12-27 15:23:39 +00:00
import { create } from 'zustand';
import { ILotteryResponse } from '@/models/lottery/lottery.model';
2025-01-02 12:47:39 +00:00
import { persist } from 'zustand/middleware';
2024-12-23 19:13:36 +00:00
interface LotteryAuthState {
isAuthenticated: boolean;
lotteryData: ILotteryResponse | null;
2024-12-27 15:23:39 +00:00
phone: string | null;
code: string | null;
setAuth: (data: ILotteryResponse, phone: string, code: string) => void;
2024-12-23 19:13:36 +00:00
logout: () => void;
}
2025-01-02 12:47:39 +00:00
export const useLotteryAuth = create<LotteryAuthState>()(
persist(
(set) => ({
isAuthenticated: false,
lotteryData: null,
phone: null,
code: null,
setAuth: (data, phone, code) =>
set({
isAuthenticated: true,
lotteryData: data,
phone,
code,
}),
logout: () =>
set({
isAuthenticated: false,
lotteryData: null,
phone: null,
code: null,
}),
}),
{
name: 'lottery-auth-storage',
},
),
);