End app sessions
An app signs the user out. A second call revokes the session's access key.
Overview
accounts.signOut() ends the app's session, and revokes its refresh token (RFC 7009). The user's Tempo ID session stays, so other apps stay signed in. The access token and the access key outlive the sign-out, since APIs verify the token on their own, and the chain holds the access key:
| Part of the session | After signOut |
|---|---|
| Session of the app | Empty at once. The saved session is deleted |
| Refresh token | Revoked at Tempo ID |
| Access token | Valid until it expires, at most 5 minutes later |
| Access key | Valid until its expiry, unless the app revokes it |
| Tempo ID session | Stays. The next sign-in asks for no email address |
The demo signs a user in and out of the app, and shows the session's status after each step.
Walkthrough
The web example runs these steps in a React app.
Create the instance
The react plugin adds the useSession hook.
import { Accounts } from 'accounts'
import { react } from 'accounts/react'
export const accounts = Accounts.create({
chain: 'testnet',
plugins: [react()],
})Render the status
useSession returns the session and its status, such as pending before the restore ends, and renders again at each change.
Outside React, session.status holds the same status, and its listener receives the new status and the previous one.
import { accounts } from './tempo.config.js'
export function App() {
const { session, status } = accounts.useSession()
if (status === 'pending') return <p>Checking the session…</p>
if (!session)
return (
<button onClick={() => void accounts.dialog.signIn()} type="button">
Sign in with Tempo
</button>
)
return <p>Signed in as {session.user.email}</p>
}import { Accounts } from 'accounts'
import { react } from 'accounts/react'
export const accounts = Accounts.create({
chain: 'testnet',
plugins: [react()],
})Sign the user out
signOut empties the session at once, also when the revocation fails.
import { accounts } from './tempo.config.js'
export function App() {
const { session, status } = accounts.useSession()
if (status === 'pending') return <p>Checking the session…</p>
if (!session)
return (
<button onClick={() => void accounts.dialog.signIn()} type="button">
Sign in with Tempo
</button>
)
return <p>Signed in as {session.user.email}</p>
return (
<main>
<p>Signed in as {session.user.email}</p>
<button onClick={() => void accounts.signOut()} type="button">
Sign out
</button>
</main>
)
}import { Accounts } from 'accounts'
import { react } from 'accounts/react'
export const accounts = Accounts.create({
chain: 'testnet',
plugins: [react()],
})The instance saves a signed-out mark, so a reload restores no session until the next sign-in.
If Tempo ID does not answer the revocation, such as offline, signOut rejects with server_error and status 0, but the session is empty. The store keeps the refresh token for the next signOut to revoke.
Revoke the access key
A sign-out leaves the access key valid on the chain. To revoke it, call dialog.revokeAccessKey before signOut, in a click handler, since a popup opens only within the gesture. The account owner signs the revocation on Tempo ID's approval page, because the chain refuses keychain changes from an access key.
import { accounts } from './tempo.config.js'
export function SignOut() {
async function signOut() {
const { session } = accounts.session.status.get()
if (session?.accessKey) await accounts.dialog.revokeAccessKey()
await accounts.signOut()
}
return (
<button onClick={signOut} type="button">
Sign out
</button>
)
}import { Accounts } from 'accounts'
import { react } from 'accounts/react'
export const accounts = Accounts.create({
// Each sign-in requests an access key that sends up to 100 OUSD for a day.
accessKey: () => ({
expiry: '1d',
limits: [{ limit: '100', token: 'ousd' }],
}),
chain: 'testnet',
plugins: [react()],
})It returns the revoking transaction's hash, or null for an access key revoked already. A Cancel throws Accounts.RequestError with access_denied, and the session stays.
With the viem plugin, accessKey.revokeSync revokes the session's own access key with no page, for any sign-in plugin. It sends the session's access token, and Tempo ID's cloud wallet signs as the owner.
The session then keeps the access key without its private key. A transaction before the sign-out thus throws Accounts.AccessKeyRequiredError, and on a page a transfer opens Tempo ID's payment page.
An account that only a passkey owns throws Accounts.RequestError with webauthn_required. Revoke its access key in the dialog.
Use cases
The use case sets the only option of signOut.
Sign out of every app
everywhere also ends the user's Tempo ID session, which signs the user out of every app. Only a first-party app may set it, as End all sessions shows.
import { accounts } from './tempo.config.js'
export function SignOut() {
return (
<button
onClick={() => accounts.signOut({ everywhere: true })}
type="button"
>
Sign out of every app
</button>
)
}import { Accounts } from 'accounts'
export const accounts = Accounts.create({
chain: 'testnet',
clientId: 'example-app',
})