Sign-in
A Members app signs its own users in. Accounts are user records and each signed-in browser is a session record; web/lib/auth.ts is the code, and the starter has every flow working before you change a line.
How people sign in
| Method | How | Needs |
|---|---|---|
| Email and password | /sign-up makes the account through the user model's signUp action and sends a confirmation; /sign-in checks the password. Inference Bureau hashes passwords on save and never returns them, so the app asks checkPassword rather than comparing. | Nothing |
| An emailed link | Email me a sign-in link on the sign-in page (/sign-in/email) sends a link good for 15 minutes and one use. The page it opens (/sign-in/link) signs in from a button rather than on opening, since mail scanners open links before people do. An address with no account gets the same answer, and a link never creates one. | |
| Google or GitHub | Continue with Google or GitHub on the sign-in and sign-up pages, shown for each provider that's connected. See below. | Your own OAuth client, connected on Settings → Integrations |
Where the app can't send email (production without Resend), the sign-in page leaves out the emailed link and Forgot your password?, and the account page leaves out sending the confirmation again: they check emailReady() || emailToLogs() from web/lib/email.ts. Google and GitHub work without email.
The user and session models
| Model | Fields | Actions |
|---|---|---|
user | email (required, unique), password (a password field), emailVerified, the hashes and expiries of its confirmation, reset and sign-in links, googleId and githubId (unique), and sessions | signUp takes only email and password from what's passed, lowercases the email, refuses passwords under 8 characters and sets emailVerified itself. update leaves the password, emailVerified, the link fields and the provider ids alone; sendVerifyEmail, verifyEmail, sendResetPassword, resetPassword, sendSignInLink, signInWithLink, linkProvider and signUpWithProvider are the only ways those change. |
session | user (belongs to user), tokenHash (unique), expiresAt | None of its own: web/lib/auth.ts creates and deletes them |
The browser's __Host-session cookie holds a random token; the record holds only the token's SHA-256 hash, so reading records never lets anyone sign in. Sessions last 30 days (DAYS in web/lib/auth.ts). The cookie is httpOnly, secure and sameSite: "lax", and its __Host- name means only the app's own address can set it: another app's page on inferencebureau.app can't plant a session of its choosing. Keep it that way. (Apps made before November 15, 2026 call it session; renaming it in web/lib/auth.ts signs everyone out once.) Signing out deletes the record; a password reset deletes every session of the user, signing every browser out, then signs the one that reset in.
web/lib/auth.ts
Server code only: pages, layouts, route handlers and server actions. Nothing in it reaches the browser.
| Function | Does |
|---|---|
currentUser() | The signed-in user record, or null: finds the cookie's session by its hash and checks it hasn't expired. |
requireUser() | The signed-in user, or a redirect to /sign-in. |
signIn(email, password) | Checks the password with checkPassword and starts a session. Returns { error } with the message to show: the same one whether the email or the password is wrong, or the message from a sign-in limit. |
signUp(email, password) | Runs the signUp action, signs the account in and sends the confirmation. An email that's taken, or a refused value, comes back as error. |
signOut() | Clears the cookie and deletes the session record. |
sendVerifyEmail(user), verifyEmail(token) | The confirmation link, good for 24 hours. |
sendResetPassword(email), resetPassword(token, password) | The reset link, good for an hour. |
sendSignInLink(email), signInWithLink(token) | The sign-in link, good for 15 minutes. Signing in with it also confirms the email; on an account nobody had confirmed, it clears the password and other sessions, since whoever made the account may not own the address. |
signInWithProvider(profile) | What the Google and GitHub callbacks call with what the provider confirmed. See below. |
The forms post to the server actions in web/app/auth-actions.ts; web/app/auth-form.tsx and email-forms.tsx draw them. Links in the emails start with IB_APP_URL, the environment's own address, so they work from development and production alike.
Members-only pages
Pages under web/app/(signed-in)/ are for members; the folder's name isn't part of the URL. Its layout.tsx calls requireUser(), but Next.js renders a layout and its page at the same time, so the layout's check doesn't protect the page: every members-only page, route handler and server action calls requireUser() itself (or currentUser() and answers 401).
// web/app/(signed-in)/projects/page.tsx
import { createClient } from "@inferencebureau/apps-sdk";
import { requireUser } from "../../../lib/auth";
export const dynamic = "force-dynamic";
export default async function Projects() {
const me = await requireUser(); // redirects to /sign-in when no one is
const page = await createClient().project.findMany({ filter: { user: { equals: me.id } }, first: 50 });
return <ul>{page.records.map((p) => <li key={p.id}>{String(p.name)}</li>)}</ul>;
}- Take the user only from
currentUser()orrequireUser(), never from an id in a form, a query string or a body. - Store
useron the records a member creates and filter every list by it. The app's own client reaches every record; the filter is what keeps one member out of another's. - Pages that read records are
export const dynamic = "force-dynamic", so a production build doesn't try to read them at build time. See Next.js on the platform. - Server actions are protected against cross-site posts by Next.js. A route handler that changes data should take JSON, which a cross-site form can't send.
- Nothing stops a user who hasn't confirmed their email. To require it, check
user.emailVerifiedinrequireUser(), or on the pages that need it.
The signed-in role
web/lib/auth.ts and any code using plain createClient() run as the environment itself and reach every record. The browser never gets that client: AutoTable, AutoForm and the hooks call the app's records route, web/app/api/records/route.ts, which answers as the signed-in user's role. createClient().asRole("signed-in", { userId }) is a client held to that role's grants in accessControl/permissions.ib.ts, with { $session: "userId" } in a filter standing for the user's id. The starter's role reads only the user's own record; grant it the models your pages show.
// accessControl/permissions.ib.ts
export const permissions: AppPermissions = {
type: "ib/permissions/v1",
roles: {
"system-admin": { default: { read: true, action: true } },
unauthenticated: {},
"signed-in": {
models: {
user: { read: { filter: { id: { equals: { $session: "userId" } } } } },
// What the pages show through AutoTable, AutoForm and the hooks: a member's own projects.
project: { read: { filter: { user: { equals: { $session: "userId" } } } }, actions: { create: true, update: true } },
},
},
},
};The route answers 401 when no one is signed in, and the hooks carry the user's cookie as any same-origin request does. See Access control for what a grant can say.
Accounts, members and roles
A user belongs to accounts (teams, organizations, workspaces: rename the model as you like) through member records, each with a role, owner, admin or member, and acts in one account at a time, kept on their session. Signing up makes the user their own account as its owner. /team lists the account's members, lets owners and admins change roles, remove people and invite by email, lets owners rename it, and switches between a user's accounts. An invitation is an invitation record whose link's token hash and expiry the send action stores (seven days), sent with web/emails/invitation.tsx; the link opens /invite, which accepts it when the person is signed in, or keeps the token in a cookie while they sign in or up, after which the sign-in accepts it. The accept action makes the member once; changeRole and delete keep an account's last owner. web/lib/team.ts holds the helpers: requireMembership() for team pages, memberships, invite, acceptInvitation, switchAccount, createAccount.
The records route holds a signed-in user's calls to several roles at once, rolesFor(user, membership): signed-in, the names in the user's roles field (a roleList, for app-wide roles such as staff), and account-admin or account-member for their standing in the account; their grants add up. A model that belongs to an account has account: { type: "belongsTo", parent: { model: "account" } }, and permissions.ib.ts grants it to account-member with { filter: { account: { equals: { $session: "accountId" } } } }, so every member sees their account's records and no one else's. Server code checks canManage(membership.role) itself and reads with createClient(), as the team page does. Apps created before November 12, 2026 have the single signed-in role and no accounts; the models and web/lib/team.ts can be copied from a new app.
The account page
web/app/(signed-in)/account/page.tsx shows the user's email with whether it's confirmed (and a button to send the confirmation again), when they joined, their record's id, and Sign out. Add pages beside it in (signed-in)/. To let a user change their password, add an action that checks the current one with checkPassword first, then sets password; never widen update to take it.
// api/models/user/actions/changePassword.ts: check the current password first, then set the new one.
export const run: ActionRun = async ({ params, record, api }) => {
const ok = await api.user.checkPassword(record.id, String(params.current));
if (!ok) throw new Error("That isn't your current password.");
record.password = String(params.next);
await save(record);
};Confirmation, reset and sign-in links
Each link carries a random token. The app makes the token and passes only its hash to the user's actions, which store it with an expiry: 24 hours to confirm, 1 hour to reset, 15 minutes to sign in. When the link is used, the matching action checks the hash and expiry again and clears them, so a link works once; asking again replaces the earlier link. /forgot-password and /sign-in/email answer the same whether or not the email has an account. The emails themselves are templates in web/emails/: see Email.
Sign-in limits
Inference Bureau counts failed sign-ins. signIn passes the email typed and the visitor's IP to checkPassword: the IP is the x-ib-client-ip header the router puts on every request to the app, from its own view of the connection, so a visitor can't set it. Each check is counted before the password is looked at, so guesses sent all at once are held to the limit too: per account (whatever email comes with it), per email, and per IP. After 10 attempts on an account or an email, or 50 from an IP, within 15 minutes, checkPassword throws an ApiError with status 429 and a message saying when to try again, without checking, until the 15 minutes are up; signIn shows that message. A correct password clears the account's and the email's counts, and doesn't count toward the IP's. An unknown email is counted like a known one, and checked for as long, so the limit doesn't say which emails have accounts. Anything else that checks a password passes the same options.
Google and GitHub
Connect each on Settings → Integrations with your own Google OAuth client (a Web application client in Google Cloud) or GitHub App. The drawer lists each environment's callback URL to register with the provider, <IB_APP_URL>/auth/google/callback or /auth/github/callback, checks the client ID and secret with the provider, and saves them as GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET, or GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET. web/lib/oauth.ts does the rest: /auth/<provider> starts (a ten-minute oauth cookie holds the state and PKCE verifier), /auth/<provider>/callback finishes and calls signInWithProvider, and ProviderButtons shows a button for each provider that's set up.
Who it signs in: the account that signed in with that provider before; else the account with the email the provider confirmed, which it links to; else a new account without a password, with the email confirmed. Linking an account whose email was never confirmed clears its password and sessions, since whoever made it may not own the address. A provider account with no confirmed email reaches only an account it's already linked to. Failures come back to /sign-in?error=<code>, shown in words from OAUTH_ERRORS.
A domain added later changes production's IB_APP_URL, and with it the callback URL. Register the new one at Google or GitHub too, or production's provider sign-in stops with a redirect mismatch.
Preview as a user
On Preview, Preview as opens development's preview signed out or as any of development's user records (admins only), in the account of your choice when they belong to several. Choosing a user creates a session record for them, good for a day, and sets the app's own __Host-session cookie (and session, which apps made before November 15, 2026 read) in the preview frame, so currentUser() finds them as it would after a sign-in; nothing in the app's code knows the difference. The cookie stays in the preview: opening the app in a new tab starts signed out. Production can't be previewed as a user, and the menu needs the starter's user and session models.
Older apps and recipes
Apps created before November 10, 2026 keep the sign-in they were made with: email and password, confirmation and reset, without the emailed link, Google and GitHub, or templates in web/emails/. A recipe's sign-in is the recipe's own, and its web-sign-in skill describes that one. The starter's files are ordinary files in your app: an older app can take the newer ones from a new app, file by file.