added forgotten local auth file

This commit is contained in:
Carter 2026-05-19 16:06:48 -06:00
parent ae9abaf9fd
commit c549372262

View file

@ -0,0 +1,44 @@
import { useAuth0 } from "@auth0/auth0-react"
import { createContext, PropsWithChildren, useContext } from "react"
interface IAuthContext {
isAuthenticated: boolean
loginWithRedirect: () => void
logout: () => void
}
const AuthContext = createContext<IAuthContext>({
isAuthenticated: false,
loginWithRedirect: () => {},
logout: () => {},
})
export function LocalAuthProvider(props: PropsWithChildren<{ token: string }>) {
const { children, token } = props
const doLogout = () => {
localStorage.removeItem('local_auth_token')
window.location.href = '/'
}
return (
<AuthContext.Provider
value={{
isAuthenticated: !!token,
loginWithRedirect: doLogout,
logout: doLogout,
}}
>
{children}
</AuthContext.Provider>
)
}
export function Auth0AuthBridge(props: PropsWithChildren<{}>) {
const { isAuthenticated, loginWithRedirect, logout } = useAuth0()
return (
<AuthContext.Provider value={{ isAuthenticated, loginWithRedirect, logout: () => logout({ logoutParams: { returnTo: window.location.origin } }) }}>
{props.children}
</AuthContext.Provider>
)
}
export const useAuthContext = () => useContext(AuthContext)