Session dialogs
Sign back in when a session expires mid-task without losing the page, and warn before an idle sign-out.
Status: beta. Category: Auth.
import { SessionExpiredDialog, IdleWarningDialog } from '@glyphui/auth/ui'
Exports: SessionExpiredDialog, IdleWarningDialog.
Notes
- Render both once near the root, inside AuthProvider.
- SessionExpiredDialog opens when auth.fetch gets a 401 that a refresh can’t fix, or when you call auth.markExpired().
- It can’t be dismissed by Escape or clicking outside: the user signs in again or signs out.
- IdleWarningDialog needs idleTimeout on the client; activity before the warning resets the timer.
SessionExpiredDialog props
| Prop | Type | Default | Description |
|---|---|---|---|
onSignOut | (() => void) | Called after the user chooses to sign out instead of signing back in. |
Example: Expired session
Revoke the session “on the server”, then call the API: the dialog asks for the password (pw).
import { AuthProvider, useAuth } from '@glyphui/auth'
import { memoryAdapter } from '@glyphui/auth/memory'
import { SessionExpiredDialog } from '@glyphui/auth/ui'
import { Button, Text, toast } from '@glyphui/ui'
const adapter = memoryAdapter({
latency: 300,
users: [{ email: '[email protected]', password: 'pw', name: 'Ada Lovelace' }],
})
function Demo() {
const { user, signIn, refresh } = useAuth()
if (!user)
return (
<Button onClick={() => signIn({ email: '[email protected]', password: 'pw' })}>
Sign in as Ada
</Button>
)
return (
<div className="grid justify-items-center gap-3">
<Text tone="muted">Signed in as {user.name}.</Text>
<div className="flex flex-wrap gap-2">
<Button
variant="outline"
onClick={() => {
adapter.expireSession()
toast('Session revoked on the server')
}}
>
Revoke session
</Button>
{/* Any API call through auth.fetch would do the same; refresh() asks the server directly. */}
<Button onClick={() => refresh()}>Call the API</Button>
</div>
</div>
)
}
export default function Example() {
return (
<AuthProvider adapter={adapter} syncTabs={false}>
<Demo />
<SessionExpiredDialog />
</AuthProvider>
)
}