mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-16 09:39:09 +00:00
Merge branch 'gcf' into main
Signed-off-by: Katalina Okano <git@kat.cafe>
This commit is contained in:
commit
156bd8f06e
364 changed files with 5234 additions and 22248 deletions
42
src/providers/auth/AuthContext.tsx
Normal file
42
src/providers/auth/AuthContext.tsx
Normal file
|
@ -0,0 +1,42 @@
|
|||
import * as React from 'react';
|
||||
|
||||
type AuthContextType = {
|
||||
sessionKey: string | null;
|
||||
setSessionKey: (value: string | null) => void;
|
||||
};
|
||||
|
||||
type Props = {
|
||||
sessionKey: string | null;
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
const AuthContext = React.createContext<AuthContextType>({
|
||||
sessionKey: null,
|
||||
setSessionKey: () => {},
|
||||
});
|
||||
|
||||
export const AuthProvider = (props: Props) => {
|
||||
const [sessionKey, setSessionKey] = React.useState(props.sessionKey);
|
||||
|
||||
return (
|
||||
<AuthContext.Provider value={{ sessionKey, setSessionKey }}>
|
||||
{props.children}
|
||||
</AuthContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useAuth = () => {
|
||||
const authCtx = React.useContext(AuthContext);
|
||||
if (!authCtx) {
|
||||
throw new Error('useAuth used without AuthProvider');
|
||||
}
|
||||
|
||||
return authCtx;
|
||||
};
|
||||
|
||||
export const isAuthenticated = () => {
|
||||
const authCtx = useAuth();
|
||||
return authCtx.sessionKey !== null;
|
||||
};
|
||||
|
||||
export const;
|
1
src/providers/auth/index.ts
Normal file
1
src/providers/auth/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './AuthContext';
|
Loading…
Add table
Add a link
Reference in a new issue