Add OpenBao API client, session context and connect screen
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c5dbb78d1b
commit
de36c97f36
9 files changed
+438
-4
No files matched your search
@@ -0,0 +1,18 @@
|
||||
import { useMemo, useState, type ReactNode } from 'react'
|
||||
import type { BaoClient, TokenInfo } from './bao'
|
||||
import { SessionContext, type Session } from './useSession'
|
||||
|
||||
// The token lives only in React state (memory); a page reload logs out.
|
||||
export function SessionProvider({ children }: { children: ReactNode }) {
|
||||
const [state, setState] = useState<{ client: BaoClient; tokenInfo: TokenInfo } | null>(null)
|
||||
const value = useMemo<Session>(
|
||||
() => ({
|
||||
client: state?.client ?? null,
|
||||
tokenInfo: state?.tokenInfo ?? null,
|
||||
connect: (client, tokenInfo) => setState({ client, tokenInfo }),
|
||||
disconnect: () => setState(null),
|
||||
}),
|
||||
[state],
|
||||
)
|
||||
return <SessionContext value={value}>{children}</SessionContext>
|
||||
}
|
||||
Reference in new issue
Block a user