11import { createContext , useContext } from "react" ;
22import { createStore , useStore } from "zustand" ;
33
4- import { AUTH_KEY } from "@/features/auth/models/storage-keys" ;
4+ import { IS_AUTHENTICATED_STORAGE } from "@/features/auth/models/storage-keys" ;
55import type { User } from "@/features/auth/models/user" ;
66import { getUser } from "@/features/auth/providers/get-user" ;
77import { AUTH_TOKEN_KEY } from "@/lib/http/ky-client" ;
88
99import { loginUser , type ICredentials } from "../providers/login-user" ;
1010
1111// could be also https://www.npmjs.com/package/zustand-persist lib for advanced use cases
12- const isLoggedIn = ( ) => localStorage . getItem ( AUTH_KEY ) === "true" ;
12+ const isLoggedIn = ( ) =>
13+ localStorage . getItem ( IS_AUTHENTICATED_STORAGE ) === "true" ;
1314
1415interface IStore {
1516 isAuthenticated : boolean ;
@@ -71,15 +72,15 @@ export const initializeAuthStore = (preloadedState: Partial<IStore> = {}) => {
7172 localStorage . setItem ( AUTH_TOKEN_KEY , token ) ;
7273 const user = await getUser ( ) ;
7374
74- localStorage . setItem ( AUTH_KEY , "true" ) ;
75+ localStorage . setItem ( IS_AUTHENTICATED_STORAGE , "true" ) ;
7576
7677 set ( {
7778 isAuthenticated : true ,
7879 state : "finished" ,
7980 user,
8081 } ) ;
8182 } catch ( e ) {
82- localStorage . setItem ( AUTH_KEY , "false" ) ;
83+ localStorage . setItem ( IS_AUTHENTICATED_STORAGE , "false" ) ;
8384
8485 set ( {
8586 isAuthenticated : false ,
@@ -96,7 +97,7 @@ export const initializeAuthStore = (preloadedState: Partial<IStore> = {}) => {
9697 } ) ;
9798
9899 return new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) ) . then ( ( ) => {
99- localStorage . setItem ( AUTH_KEY , "false" ) ;
100+ localStorage . setItem ( IS_AUTHENTICATED_STORAGE , "false" ) ;
100101 localStorage . removeItem ( AUTH_TOKEN_KEY ) ;
101102 set ( {
102103 isAuthenticated : false ,
0 commit comments