Advertisement
MrB4RC0D3

auth-slice.tsx

Apr 15th, 2024
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TypeScript 0.55 KB | Source Code | 0 0
  1. import { StateCreator } from "zustand";
  2.  
  3. export interface AuthSlice {
  4.     isAuthenticated: boolean;
  5.     user: string | null;
  6.     setUser: (username: string) => void;
  7.     logout: () => void;
  8. }
  9.  
  10. export const createAuthSlice: StateCreator<AuthSlice, [], [], AuthSlice> = (set) => ({
  11.     isAuthenticated: false,
  12.     user: null,
  13.     setUser: (username) => (set((_state) => ({ user: username, isAuthenticated: true })), console.log(username)),
  14.     logout: () => (set((_state) => ({ user: null, isAuthenticated: false })), console.log("Logging out...")),
  15. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement