Guides
GuideAuthentication

Authentication

Add user accounts to your published app. Users can sign up, log in, and access data based on their role.

Enable authentication in your app's Config tab. Once enabled, users can sign up and log in. Their identity is automatically passed to access rules and backend functions.

How It Works

1

User signs up

With email, password, and optional custom fields (name, company, etc.).

2

JWT token issued

A signed JWT token is stored in a secure httpOnly cookie. Valid for 7 days with automatic refresh.

3

Identity flows through

Every API call from the SDK automatically includes the token. Access rules evaluate against the user's identity, role, and profile data.

Enabling Authentication

  1. Go to your app's Config tab in the dashboard
  2. Toggle Enable Authentication on
  3. Optionally configure custom signup fields (e.g., "Company", "Phone")
  4. Publish your app for the changes to take effect

When auth is enabled, your app automatically gets login and signup pages. You don't need to build them yourself.

Signup & Login

FeatureDetails
Email/PasswordDefault auth method. Password requires 8+ characters, uppercase, lowercase, and a digit.
Email verification and linksWhen your site asks new members to verify their email, the emailed link verifies the address and opens a “Set your password” step on your reset-password page (the one your site already has): the password typed at sign-up never counts, it is cleared the moment the link is used (anyone could have signed up with that address), and the member is signed in once they choose a new one, which works at once. Opening the link again before that gives a fresh step. When you change a member's email, every reset or verify link sent to the old address stops working and they are signed out. A suspended member's links do nothing.
Custom signup fieldsAdd fields like Name, Company, Phone to the signup form. Stored in the user's profile data. A profile field that any of your site's access rules reads (a row, page, file or function rule, a tenant's create or join rule, a secret's use rule) can only be set by you: a visitor who sends a different value on sign-up or a profile update is refused (“"<field>" can only be set by the site's owner.”) and nothing is saved; sending back the stored value, or leaving an unset field empty, is ignored.
Back to the page after sign-inSend visitors to /login?return_to=/your-page (a pricing page: /login?return_to=/pay). Login, sign-up and email verification all keep it and bring them back there. Only a path on your own site is followed; anything else goes to the after-login page below.
After-login pageWhere the built-in login, sign-up and email-verification pages send a member after signing in when no return_to is kept: authPaths.afterLogin, for example /dashboard when your home page is a public page. return_to wins over it. Not set, or not a path on your own site: the home page (/). Set it from the AI chat or your own AI client (site_updateProjectAuth); like the other page paths it reaches the live site at the next publish. A login page you built yourself decides for itself where to go.
Who uses this siteIndividuals (the default): each member is on their own. Multi-tenant: each new sign-up gets its own tenant (a company, a shop, a class) of the tenant type you pick, and is its tenant admin; the tenant is named from the sign-up field you pick (for example Company), else the person's name. A tenant's own customer signs up with tenant: 'none' and joins no tenant. Switching never creates or deletes anything for people who already signed up. Set it in the site's Authentication settings (shown while sign-in is on), or from the AI chat or your own AI client (site_updateProjectAuth); page code reads it with user.siteUsers().
Token expiry7 days. Tokens refresh automatically.
Logout all sessionsIncrement the user's tokenVersion to instantly invalidate all existing tokens.
Custom auth pathsThe login, signup, forgotPassword, resetPassword and verifyEmail page paths, and afterLogin (above). Any other key is stored but does nothing.
Social loginNot implemented. The "Allow social login" toggle exists in Config but has no effect — email/password is the only method.

Roles

Roles are first-class, per-project entities with stable IDs — not a free-text list on the user's profile. Create a role, then assign it to users; access rules reference the role's ID.

Common roles:

  • admin — Full access to manage all data
  • editor — Can create and modify content
  • viewer — Read-only access

Define any custom roles from the dashboard, then use the has_role access rule (with the role's roleId) to restrict access.

A custom signup field named roles does nothing — role membership never comes from profile data a user can submit. Roles are only granted by the app owner, from the Users tab or via assignRoleToAppUser.

Manage user roles from the dashboard under your app's Users section. See Access Control for how to use roles in access rules.

Using Auth in Your App

The SDK provides auth methods in your published app:

// Import user from the SDK
import { user } from '../api/sdk';

// Get current user
const me = await user.me();
// { id, email, name, role, profileData, roleIds, roles, isAppSuperAdmin, emailVerified, createdAt } or null

// Login with credentials
await user.loginWithCredentials(email, password);

// Or redirect to login page
user.login();

// Signup
await user.signup(email, password, name);

// Back to the page that sent them to sign in (?return_to=/pay), or '/' (paths on your site only)
navigate(user.returnTo('/'));

// Logout
await user.logout();

Signup and login also return the token directly in the response body (in addition to setting the cookie) — useful for apps on a custom domain that can't rely on a first-party cookie.

Security Details

Passwords hashed with bcrypt

Passwords are never stored in plain text.

JWT tokens in httpOnly cookies

Tokens cannot be accessed by JavaScript, preventing XSS attacks.

Project-scoped tokens

Each token includes the project ID. Tokens from one app cannot be used on another.

Instant session revocation

Increment tokenVersion to invalidate all sessions for a user immediately.