Commit 83b3bcdd by G

authenticationData state

parent 4a40ec39
import { createContext, useContext, useState } from "react"; import { createContext, useContext, useState } from "react";
import type { IauthenticationData } from "./Types";
export interface UserAuthenticationContextProps { export interface UserAuthenticationContextProps {
isAuthenticated: boolean; isAuthenticated: boolean;
setIsAuthenticated: React.Dispatch<React.SetStateAction<boolean>>; setIsAuthenticated: React.Dispatch<React.SetStateAction<boolean>>;
setAuthenticationData: React.Dispatch<React.SetStateAction<IauthenticationData>>;
} }
export const UserAuthenticationContext = createContext<UserAuthenticationContextProps>({ export const UserAuthenticationContext = createContext<UserAuthenticationContextProps>({
isAuthenticated: false, isAuthenticated: false,
setIsAuthenticated: () => {}, setIsAuthenticated: () => {},
setAuthenticationData: () => {},
}); });
export const UserAuthenticationContextProvider = ({ children }: { children: React.ReactNode }) => { export const UserAuthenticationContextProvider = ({ children }: { children: React.ReactNode }) => {
const [isAuthenticated, setIsAuthenticated] = useState(false); const [isAuthenticated, setIsAuthenticated] = useState(false);
const [authenticationData, setAuthenticationData] = useState<IauthenticationData>({
access: "",
refresh: "",
});
return ( return (
<UserAuthenticationContext.Provider <UserAuthenticationContext.Provider
value={{ isAuthenticated: isAuthenticated, setIsAuthenticated }} value={{ isAuthenticated: isAuthenticated, setIsAuthenticated, setAuthenticationData }}
> >
{children} {children}
</UserAuthenticationContext.Provider> </UserAuthenticationContext.Provider>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment