login(); there are no separate access or refresh tokens. Most apps don’t use this hook directly; MonacoProvider wires it up and useAuth drives it. See React SDK setup.
Parameters
MonacoSDK | null
required
Monaco SDK instance from
useMonacoSDK()TokenLifecycleConfig
Session lifecycle options:
autoRefresh: boolean (default:true) - automatically extend the session before it expirespersistTokens: boolean (default:true) - persist the session inlocalStorageso it survives reloadsrefreshBufferSeconds: number (default:300) - how long before expiry to trigger a refreshonRefreshError:(error: Error) => void- called when a refresh failsonRefreshSuccess:(authState: AuthState) => void- called when a refresh succeeds
Return Values
(authState: AuthState) => void
Start managing a session. Call after a successful
login(); persists the session (if enabled) and schedules auto-refresh.() => void
Stop managing the session, cancel scheduled refreshes, and remove the persisted session. Call on logout.
() => Promise<AuthState | null>
Extend the session’s expiry now (via
sdk.refreshAuth()). Returns the updated AuthState, or null if there is no active session or the refresh fails.(authState: AuthState | null) => boolean
Whether the session is expired or within the refresh buffer of expiry.
Example
How It Works
- Auto Refresh: when enabled, schedules a session refresh
refreshBufferSecondsbefore expiry. - Persistence: saves the session to
localStorageso it can be restored after a reload. - Deduplication: collapses concurrent refresh calls into a single request.
- Cleanup: clears scheduled timers on unmount.
This is an advanced hook. For most apps,
MonacoProvider + useAuth manage the session automatically.
