feat: initial auth provider
This commit is contained in:
29
src/providers/AuthProvider.tsx
Normal file
29
src/providers/AuthProvider.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import { signal, Signal } from "@preact/signals";
|
||||
import { createContext, JSX } from "preact";
|
||||
import { useContext } from "preact/hooks";
|
||||
|
||||
interface AppContextValue {
|
||||
isLoggedIn: Signal<boolean>;
|
||||
}
|
||||
|
||||
const AppContext = createContext<AppContextValue>({
|
||||
isLoggedIn: signal(false),
|
||||
});
|
||||
|
||||
const AppProvider = ({ children }: { children: JSX.Element }) => {
|
||||
const value: AppContextValue = {
|
||||
isLoggedIn: signal(false),
|
||||
};
|
||||
|
||||
return <AppContext.Provider value={value}>{children}</AppContext.Provider>;
|
||||
};
|
||||
|
||||
const useAppContext = () => {
|
||||
const context = useContext(AppContext);
|
||||
if (!context) {
|
||||
throw new Error("useAppContext must be used within AppProvider");
|
||||
}
|
||||
return context;
|
||||
};
|
||||
|
||||
export { AppProvider, useAppContext };
|
||||
Reference in New Issue
Block a user