The browser sends the session's access token to your API. Your server asks Scute who it belongs to with getUser(token), which calls GET /v1/auth/:app_id/current_user with the token.
Check a token#
import { createClient, InvalidAuthTokenError } from "@scute/js-core";const scute = createClient({ appId: process.env.SCUTE_APP_ID });export async function userFrom(authorization: string | undefined) { const token = authorization?.replace(/^Bearer /, ""); if (!token) return null; const { data, error } = await scute.getUser(token); if (error instanceof InvalidAuthTokenError) return null; // refused: expired, revoked or forged if (error) throw error; // Scute unreachable or 5xx return data.user;}| Result | Meaning |
|---|---|
| { data: { user } } | The token is valid. user is ScuteUserData. |
| { error: InvalidAuthTokenError } | The API refused the token (401). |
| { error: BaseHttpError } | Another API error. error.code is the status. |
Each call is a request to Scute. Concurrent calls with the same token share one request.
Send the token from the browser#
const { data } = await scute.getAuthToken();await fetch("/api/orders", { headers: { Authorization: `Bearer ${data?.access}` } });In Next.js the session is in cookies, so server code reads it without a header. See Next.js server helpers.
Offline verification#
@scute/js-core has no helper that verifies an access token's signature locally. The token is an RS256 JWT; to verify it without a request, use a JWT library with the app's public keys (see the API reference).
After the user is known#
| Next | Page |
|---|---|
| May this user do this? | Authorization |
| Only the rows this user may see | Data filters |
| Decide without a request per check | Local decisions |