Sign in
The client acts as one person, with their access token. Your server gets the token, and the client asks your server for it.
How it works
A person approves your app over OAuth, as they do for any connected app, and can see and revoke it in their Nextmail account. Your server finishes that sign-in and keeps the refresh token. Your client then asks your server for a short-lived access token.
import { createClient } from '@nextmail/mailbox' export const client = createClient({ accessToken: async () => { const response = await fetch('/api/mail-token', { credentials: 'include' }) return response.text() },}) const me = await client.me.get() console.log(me.clientId, me.expiresAt)The function is called once for every call, and that call’s retries reuse what it returned. So your server can renew the token when it nears expiry, and the client never has to be rebuilt.
An access token lasts an hour and reaches only what the person approved. Keep it in memory, never in localStorage or a cookie your page can read, so a script on the page cannot take it for long.
What it refuses
| Case | What happens |
|---|---|
| An API key, as apiKey or as accessToken | createClient throws. Anyone can read code that runs in a browser, and a key acts for the whole workspace. Keep keys on a server with @nextmail/sdk. |
| No accessToken | createClient throws. |
| A function that resolves to an API key | The call rejects, and nothing is sent. |
| A function that throws | The call rejects with that error, and nothing is sent. |
