port full auth flow to cf workers

This commit is contained in:
41666 2020-12-05 03:09:20 -05:00
parent 9eeb946389
commit aad0987dce
50 changed files with 551 additions and 1167 deletions

View file

@ -0,0 +1,40 @@
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;
};

View file

@ -0,0 +1 @@
export * from './AuthContext';