very basics of auth state - not actually authenticating anything right now....

This commit is contained in:
Will Baumbach
2025-08-05 12:04:02 -05:00
parent 813cb44637
commit 409f15f233
8 changed files with 224 additions and 23 deletions

46
app/ctx.tsx Normal file
View File

@@ -0,0 +1,46 @@
import { createContext, use, type PropsWithChildren } from 'react'
import { useStorageState } from './useStorageState'
const AuthContext = createContext<{
login: () => void
logout: () => void
session?: string | null
isLoading: boolean
}>({
login: () => null,
logout: () => null,
session: null,
isLoading: false
})
// This hook can be used to access the user info.
export function useSession() {
const value = use(AuthContext)
if (!value) {
throw new Error('useSession must be wrapped in a <SessionProvider />')
}
return value
}
export function SessionProvider({ children }: PropsWithChildren) {
const [[isLoading, session], setSession] = useStorageState('session')
return (
<AuthContext
value={{
login: () => {
// Perform sign-in logic here
setSession('admin')
},
logout: () => {
setSession(null)
},
session,
isLoading
}}
>
{children}
</AuthContext>
)
}