User token
Issue a scoped token on your backend after your own authentication.
Run this on your backend only, after authenticating your user. The variables are trusted server configuration, not values chosen by the browser.
import { createApplicationServer } from '@aimount/application-client/server';
// Your backend only. Authenticate your user first.
const server = createApplicationServer({
baseUrl: apiBaseUrl,
applicationId,
runtimeKey,
});
const operation = server.prepareUserToken({
external_user_id: authenticatedUser.id,
});
// Persist this exact operation before dispatch for recovery.
const issued = await server.issueUserToken(operation);
// Return user, token, expires_at only to this user.
// Set Cache-Control: no-store. Never expose runtimeKey.Return the token to that user only, with Cache-Control: no-store. The browser uses it until expires_at and then asks your backend for a new one.