32 lines
769 B
TypeScript
32 lines
769 B
TypeScript
import { createContext, useContext, type ReactNode } from "react"
|
|
|
|
type ConvexAuthSessionContextValue = {
|
|
invalidateSession: () => Promise<void>
|
|
}
|
|
|
|
const ConvexAuthSessionContext = createContext<ConvexAuthSessionContextValue | null>(
|
|
null
|
|
)
|
|
|
|
export function ConvexAuthSessionProvider({
|
|
children,
|
|
invalidateSession,
|
|
}: {
|
|
children: ReactNode
|
|
invalidateSession: () => Promise<void>
|
|
}) {
|
|
return (
|
|
<ConvexAuthSessionContext.Provider value={{ invalidateSession }}>
|
|
{children}
|
|
</ConvexAuthSessionContext.Provider>
|
|
)
|
|
}
|
|
|
|
export function useInvalidateAuthSession() {
|
|
const context = useContext(ConvexAuthSessionContext)
|
|
if (!context) {
|
|
throw new Error("useInvalidateAuthSession must be used within ConvexAppProvider")
|
|
}
|
|
return context
|
|
}
|