diff --git a/src/components/lume/LumeIdentity/LumeIdentityContext.ts b/src/components/lume/LumeIdentity/LumeIdentityContext.ts index d1ec73d..4887935 100644 --- a/src/components/lume/LumeIdentity/LumeIdentityContext.ts +++ b/src/components/lume/LumeIdentity/LumeIdentityContext.ts @@ -1,43 +1,48 @@ import React from "react"; export type Session = string; -export const LumeIdentityContext = React.createContext<{ - session: Session | undefined; - setSession: React.Dispatch>; -} | undefined>(undefined); +export const LumeIdentityContext = React.createContext< + | { + session: Session | undefined; + setSession: React.Dispatch>; + } + | undefined +>(undefined); export function useLumeIndentity() { const contextValue = React.useContext(LumeIdentityContext); // When the `session` changes we want to update the `session` in the local storage? React.useEffect(() => { if (contextValue?.session) { - localStorage.setItem('lume-session', contextValue.session); + localStorage.setItem("lume-session", contextValue.session); } else { - localStorage.removeItem('lume-session'); + localStorage.removeItem("lume-session"); } }, [contextValue?.session]); // Get the session from the local storage React.useEffect(() => { - const session = localStorage.getItem('lume-session'); + const session = localStorage.getItem("lume-session"); if (session) { contextValue?.setSession(session); } }, []); if (contextValue === undefined) { - throw new Error('useLumeIndentity hook is being used outside of its context. Please ensure that it is wrapped within a .'); + throw new Error( + "useLumeIdentity hook is being used outside of its context. Please ensure that it is wrapped within a ." + ); } return { isSignedIn: !!contextValue.session, signIn: (key: string) => { - console.log('signing in with key', key); + console.log("signing in with key", key); // TODO: From the key generate a session, and store it - contextValue.setSession('session'); + contextValue.setSession("session"); }, signOut: () => { contextValue.setSession(undefined); }, }; -} \ No newline at end of file +}