offline_access, Ave issues a refresh token so your app can rotate tokens without sending the user through consent again.
AveSession gives you one supported lifecycle for that work: persist the token bundle, refresh before expiry, collapse duplicate refresh calls, broadcast changes across tabs, and save rotated refresh tokens atomically.
When to use it
- You use a registered OAuth app and requested
offline_access. - You need a fresh
id_tokenfor Convex, your API, or another auth client. - You want to avoid duplicated refresh calls, stale refresh tokens, and cold-start races.
- You need framework adapters for Convex, Svelte, Next.js, or Expo.
Quick Ave does not issue refresh tokens. Move to a registered app when you need long-lived sessions. See Upgrading from Quick Ave.
Create a session
completeOAuthCallback runs finishPkceLogin and setTokensFromResponse together. Use it on your OAuth callback route, then call hydrate() during app startup.
If the redirect includes an E2EE #app_key, finishPkceLogin merges it into the token response and removes sensitive fragment parameters from the URL. session.getAppKeyBase64() returns the stored key after hydrate().
getValidIdToken() waits for proactive refresh when the JWT is near expiry. For production refresh-token handling, prefer createMemoryStorage() or a backend-for-frontend instead of localStorage. See Quickstart for storage guidance.
Convex
session.setTokensFromResponse after login. wireAveSessionToConvex passes a function that calls getValidIdToken() so Convex always receives a valid token.
Next.js App Router
UseAveSessionProvider and useAveSession from @ave-id/sdk/next. If you use Convex, AveConvexBridge can replace a manual wireAveSessionToConvex call. See Next.js App Router + Ave Session.
Svelte
onMount before relying on authenticated UI.
Expo
Native Expo has no Web Crypto for PKCE SHA-256. Configureexpo-crypto once with configureAveSdkForExpo from @ave-id/sdk/expo-session, then use AveSession with createSecureStoreAdapter and completeExpoOAuthCallback. See Expo with AuthSession.
Backend refresh
PasscustomRefresh in AveSession options to POST to your own /api/session/refresh endpoint. That endpoint can read an HttpOnly cookie and return TokenResponse-shaped JSON. The client never stores the refresh token.
E2EE app key
For registered E2EE apps, Ave may append#app_key=... after consent. finishPkceLogin merges that value into the returned TokenResponse, and AveSession stores it as appKeyBase64 next to your OAuth tokens so you can use session.getAppKeyBase64() after hydrate().
You still own crypto policy. Import the key with Web Crypto according to End-to-end encryption. FedCM flows may set app_key on the token response directly; that value is merged the same way.
Dev tools
Withdevtools: true, window.__aveSessionDev exposes getState(), expiry helpers, and lastRefreshError in development builds.
Server APIs
UsegetBearerToken and verifyAveIdTokenFromAuthHeader from @ave-id/sdk/server to turn Authorization: Bearer <id_token> into subject plus claims. See Postgres, SQLite, and JWT auth.
Related
- Convex custom auth —
applicationID, which token to pass - Why sessions still fail — troubleshooting matrix
