SessionProvider
Manages session lifecycle for Asset Studio. It must wrap the entire application (or at least all Asset Studio components) since both StudioProvider and Asset require an active session.
Usage
tsx
import { SessionProvider, SessionResponse } from '@asset-studio/core'
async function createSession(userGuid: string): Promise<SessionResponse> {
const response = await fetch('https://your-server.com/createSession', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ user_guid: userGuid }),
})
return response.json()
}
export default function App() {
return (
<SessionProvider onCreateSession={createSession}>
{/* your app */}
</SessionProvider>
)
}Props
| Prop | Type | Required | Description |
|---|---|---|---|
children | ReactNode | Yes | Your application components. |
onCreateSession | (userGuid: string) => Promise<SessionResponse> | Yes | Called on mount to obtain a session token. See Session Setup. |
SessionResponse
ts
type SessionResponse = {
session_key: string // Session identifier
end_time: string // Expiration time
reused: boolean // Whether an existing session was reused
}Behavior
- On mount, generates a unique user GUID and calls
onCreateSessionto obtain a token. - Automatically validates the token against the session check endpoint.
- Re-checks session validity every 60 minutes, with a 2-minute retry interval on failure.
- Transitions through session states:
"loading"→"valid"→"expired"or"error".
useSession
Read the current session status anywhere inside SessionProvider:
tsx
import { useSession } from '@asset-studio/core'
function SessionGuard({ children }) {
const { sessionStatus } = useSession()
if (sessionStatus === 'loading') return <div>Validating license...</div>
if (sessionStatus === 'expired' || sessionStatus === 'error') return <div>Invalid or expired session.</div>
return <>{children}</>
}Return Value
| Property | Type | Description |
|---|---|---|
sessionStatus | "loading" | "valid" | "expired" | "error" | Current state of the session. |