The handoff package
For: a developer of an Expo app or an Electron app who signs in through the system browser.
What it does: this page lists the options, the result, the opener contract, the helpers of each platform, and the failure codes. Sign in from a native or desktop app gives the steps.
Before you start
Section titled “Before you start”- Set
handoff.schemeson the API. Configuration lists the handoff keys.
createHandoff
Section titled “createHandoff”createHandoff(options) answers a Handoff. The type of the options is HandoffOptions.
| Option | Default | What it does |
|---|---|---|
baseURL |
required | The origin of the API. One trailing / is removed. |
basePath |
"/auth" |
The mount path of the routes. |
redirect |
required | <scheme>auth for a scheme of the API’s handoff.schemes, or a development URL that devRedirectPattern admits. A redirect with # is refused. |
opener |
required | The browser side, a HandoffOpener. |
fetch |
globalThis.fetch |
The fetch of the redeem. |
crypto |
webCrypto() |
The crypto seam, a PkceCrypto of the OAuth client entry. Hermes needs expoCrypto. |
signIn()answers aHandoffResult:{ ok: true, value }with aHandoffSessionof{ token, user, session }, or aHandoffFailure.signIn()is single flight. A second call while one runs gets the result of the first, and the opener runs once.startUrl(challenge)answers the start URL, for an app that opens the browser itself.
The other exports of the entry:
HandoffCodeandHandoffare types.
The opener contract
Section titled “The opener contract”An opener has one method, open(url, redirect).
- It opens
urlin the system browser. - It resolves with the full URL that the app received on
redirect. - It resolves with
nullwhen the person cancels or the wait ends. The handoff then answerscancelled. - It never resolves with a URL of another flow. One handoff waits at a time.
The returned URL must sit on the configured redirect, byte for byte. Otherwise no redeem happens, and the code is redirect_mismatch.
@authtempo/handoff/expo exports expoOpener(WebBrowser), expoCrypto(Crypto), and expoTokenStore(SecureStore).
- Add the app scheme to the
schemeentry ofapp.json. Without it, the system does not return the code to the app. expoOpenerpassespreferEphemeralSession: false. An ephemeral session keeps no cookies, so the binding cookie of a social sign-in dies, and the flow answersinvalid_token.expoCryptois required on Hermes. Hermes has nocrypto.subtle.
Electron
Section titled “Electron”@authtempo/handoff/electron exports electronOpener, createTokenStore, asyncSafeStorageCipher, safeStorageCipher, and TokenStoreError. Run all of them in the main process.
electronOpener({ shell, app })listens foropen-urlon macOS. On Windows and Linux, forward the URL ofsecond-instancetoopener.receive.createTokenStore({ cipher, read, write, remove })keeps the token encrypted at rest.asyncSafeStorageCipher(safeStorage)wraps the async functions ofsafeStorage. Use it in a new app.safeStorageCipher(safeStorage)wraps the sync functions, for an older app.- When
safeStoragehas no encryption,setthrowsTokenStoreErrorand writes nothing. On Linux thebasic_textbackend counts as no encryption. - Call
setafterappis ready. Before that, Windows and Linux report no encryption. - The token stays in the main process. A renderer asks the main process to make requests.
The path of Windows and Linux is not proven. The macOS proof ran on 2026-10-09 with Electron 44.7.0.
The native client
Section titled “The native client”createNativeClient(options) answers a NativeClient: a client of the app with credentials: "omit" and the stored token as the bearer. The type of the options is NativeClientOptions: baseURL, basePath, handoff, store, fetch, and webauthn.
signInWithBrowser()runs the handoff, writes the token to the store, and reads the session.session()clears the token when it answersnull.- A session end clears the token only when the store still holds the token that the request sent. A newer token stays.
signOut()clears the token when the server ended the session or did not know it.- A store write that throws in
signInWithBrowser()answersunexpected. A read that throws sends no token, and a clear that throws is skipped. Nothing throws for an answer. - A password sign-in, an email code verify, and a second factor verify answer a token that the native client does not keep. Write it with
store.set.
A TokenStore has get, set, and clear. On Electron, createTokenStore answers a TokenStore.
expoTokenStore(SecureStore) keeps the token through expo-secure-store, whose part it calls is SecureStoreLike.
- A key holds letters, digits,
.,-, and_only. The default isauthtempo.session. - A read that throws, as a locked keychain does, answers
nulland keeps the entry. secureStoreOptions, aSecureStoreOptionsLike, goes to each call ofexpo-secure-store.
Exports
Section titled “Exports”The main entry
Section titled “The main entry”| Entry | Exports |
|---|---|
@authtempo/handoff |
createHandoff, Handoff, HandoffOptions, HandoffOpener, HandoffResult, HandoffSession, HandoffFailure, HandoffCode, HANDOFF_CALLS, createNativeClient, NativeClient, NativeClientOptions, TokenStore |
The Expo entry
Section titled “The Expo entry”| Entry | Exports |
|---|---|
@authtempo/handoff/expo |
expoOpener, ExpoWebBrowserLike, expoCrypto, ExpoCryptoLike, expoTokenStore, SecureStoreLike, SecureStoreOptionsLike, TokenStore |
The Electron entry
Section titled “The Electron entry”| Entry | Exports |
|---|---|
@authtempo/handoff/electron |
electronOpener, ElectronOpener, ElectronShellLike, ElectronAppLike, createTokenStore, TokenStore, TokenStoreError, TokenCipher, CipherOptions, safeStorageCipher, SafeStorageLike, asyncSafeStorageCipher, AsyncSafeStorageLike |
HANDOFF_CALLS is the table of the route that the handoff builds a URL for: GET /handoff/start, which the system browser opens. The redeem is the call handoff.redeem of the client.
makePkce, webCrypto, base64Url, parseReturnedUrl, PkceCrypto, and Returned live in the OAuth client entry. Until 0.2.0 this package exported them too, with PkceCrypto under the name HandoffCrypto.
Failure codes
Section titled “Failure codes”| Code | Meaning |
|---|---|
cancelled |
The person closed the browser, or the wait ended. |
redirect_mismatch |
The returned URL is not on the configured redirect. No redeem happened. The Electron opener drops such a URL and waits on. |
| A core code | The codes of the server pass through, such as invalid_token, token_expired, and rate_limited. |
network, unexpected |
The same as in the client package. |