initial commit, boilerplate stuff
This commit is contained in:
21
src/contexts/AuthProvider.tsx
Normal file
21
src/contexts/AuthProvider.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import { ReactNode, useState } from "react";
|
||||
|
||||
import { AuthContext, type AuthContextValue } from "./AuthContext.ts";
|
||||
|
||||
import { type AuthResponse } from "../model.ts";
|
||||
|
||||
export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
const [authResponse, setAuthResponse] = useState<AuthResponse | null>(() => {
|
||||
const stored = localStorage.getItem("authResponse");
|
||||
|
||||
return stored ? JSON.parse(stored) : null;
|
||||
});
|
||||
|
||||
const value: AuthContextValue = { authResponse, setAuthResponse };
|
||||
|
||||
return (
|
||||
<AuthContext.Provider value={value}>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user