Authentication
Pulze ships every sign-in screen working on a demo adapter, so you can click through all of them before you connect anything. When you're ready, you write one adapter for your provider and every page uses it. You don't edit the pages.

The pages
| Page | Route | File | What it does |
|---|---|---|---|
| Sign in | /sign-in |
auth/sign-in.tsx |
Email + password, social buttons, "Sign in with SSO", "Email me a magic link", keep me signed in |
| Sign up | /sign-up |
auth/sign-up.tsx |
Three steps: account (password rules), workspace (name + address), invite team (skippable) |
| Forgot password | /forgot-password |
auth/forgot-password.tsx |
Asks for the email, then "Check your email" with a resend timer |
| Reset password | /reset-password?token= |
auth/reset-password.tsx |
New password with strength meter and confirm; "expired link" and "password updated" screens |
| Two-step verification | /two-step |
auth/two-step.tsx |
6-digit code, trust this device, backup code, text me a code, tries left, too many tries |
| Lock screen | /lock?from= |
auth/lock.tsx |
Clock, password or passkey to unlock, returns to the page you were on |
Shared pieces (heading, social buttons, the "or" line, resend timer) are in
auth/parts.tsx.
Settings
All in site.config.ts → auth:
auth: {
layout: "split", // or "centered"
providers: ["google", "github", "apple"], // [] hides social sign-in
sso: true, // "Sign in with SSO"
magicLink: true, // "Email me a magic link"
resetWith: "link", // or "code"
lockAfterMinutes: 15, // 0 turns the idle lock off
},
| Option | What it changes |
|---|---|
layout |
split: form on the left, product showcase on the right (hidden on phones). centered: one card on a dotted background. Every auth page follows it. |
providers |
Which social buttons show, in order. One or two show full-width "Continue with …" buttons; three show icon buttons in a row. |
sso, magicLink |
Show or hide those options under the form. |
resetWith |
link: the reset email links to /reset-password?token=…. code: it holds a 6-digit code that people type on Forgot password, which then opens /reset-password?token=<code>. Clerk, Cognito and Supabase OTP use codes. |
lockAfterMinutes |
The default idle time before the lock screen. Each person can change it in Settings › Security › Lock screen (saved in their browser). |
The legal links under the forms, "Contact support" and the status link come
from support:
support: {
email: "support@acme.io",
privacyUrl: "/privacy",
termsUrl: "/terms",
statusUrl: "https://status.acme.io",
},
The showcase (split layout)
The right-hand side is filled from data/content/auth.ts:
| Export | What it is |
|---|---|
TESTIMONIALS |
Quotes that rotate every 8 seconds (one quote = no rotation) |
SHOWCASE |
The three floating cards: revenue + trend, live visitors, a deal |
SIGNUP_FEATURES |
The three feature rows on the sign-up page |
SIGNUP_PROOF |
"Join 4,200+ teams" and its avatars |
To show something else entirely, edit Showcase or SignUpAside in
layout/auth-layout.tsx. The cards float gently and quotes cross-fade; both
stop when motion is off.
Try the demo
The demo adapter accepts everything, except these values, which show the error screens:
| Where | Type | You see |
|---|---|---|
| Sign in, lock | password wrong |
Wrong password |
| Sign up | email taken@acme.io |
"There's already an account" |
| Two-step | code 000000 |
Wrong code, tries left; after 5, "Too many tries" |
| Reset link | ?token=expired |
"This link has expired" |
Two-step only appears when it's on in Settings › Security. With
demo: true in site.config.ts a small "Demo:" hint explains this on each
page; keep demo: false in your app.
How the pages talk to your provider
Every page imports auth from @pulze/data:
// src/data/auth/index.ts
export const auth: AuthAdapter = mockAuth
AuthAdapter (in auth/types.ts) is the whole contract:
| Method | Called from | Should |
|---|---|---|
currentUser() |
anywhere | Return the signed-in person or null |
signIn({ email, password, remember }) |
Sign in | Return { next: "done" } or { next: "two-step", email } |
signInWithProvider(provider) |
Social buttons | Start Google / GitHub / Apple sign-in, same return value |
signInWithSso(email) |
"Sign in with SSO" | Send the person to their company's identity provider |
sendMagicLink(email) |
"Email me a magic link" | Email a one-time sign-in link |
signUp({ firstName, lastName, email, password }) |
Sign up, step 1 | Create the account |
createWorkspace({ name, slug, size }) |
Sign up, step 2 | Create the team / organisation |
inviteTeam(emails) |
Sign up, step 3 | Send invites |
sendPasswordReset(email) |
Forgot password | Email a reset link to /reset-password?token=… |
checkResetToken(token) |
Reset password (on load) | Return { email }, or throw link-expired |
resetPassword(token, password) |
Reset password | Set the new password |
verifyCode(code, trustDevice) |
Two-step | Check the code; throw wrong-code with triesLeft, or too-many-tries |
verifyBackupCode(code) |
Two-step › backup code | Check a backup code |
sendCodeBySms() |
Two-step › text me a code | Send the code by SMS and return the masked number |
unlock(password), unlockWithPasskey() |
Lock screen | Re-check who's there |
signOut() |
User menu, lock screen | End the session |
completeSignIn(url) (optional) |
Sign in (when it opens) | Finish a sign-in that returns to /sign-in (a magic link); else null |
When sign-in needs a second step, call setPendingEmail(email) (from
auth/pending.ts) before returning { next: "two-step", email }, and
setPendingEmail(null) once the code is accepted. The two-step page shows
that email.
After signing in, people return to the page in ?from= (set by the
protection below), or to the dashboard.
Errors are AuthError(message, code, triesLeft?). The code decides which
screen shows (wrong-password, email-taken, wrong-code,
too-many-tries, link-expired), and the message is shown to the person,
so write it in plain words.
Connect a real provider
Step-by-step guides, each with the complete adapter:
| Guide | Good for |
|---|---|
| Firebase Auth | You already use Firebase, or want a free hosted option |
| Better Auth (and Auth.js) | Accounts in your own database, everything included, open source |
| Clerk | A hosted service with a dashboard, organizations and email sending done for you |
For any other provider (Supabase, Auth0, Cognito, your own API):
- Copy
auth/mock.tstoauth/<provider>.tsand implement each method with your provider's SDK. Methods your provider doesn't support can thrownew AuthError("Not available", "unknown"), and you hide that option insiteConfig.auth. - In
auth/index.ts, changemockAuthto your adapter. - Protect the app pages (below).
- Use the signed-in person everywhere (below).
Use the signed-in person everywhere
Pages get the current person from useCurrentUser() in data/session.ts.
Until you connect sign-in it returns the sample user Maya (u_001). Read
it from your provider instead:
export function useCurrentUser(): User {
const me = useQuery({
queryKey: ["me"],
queryFn: () => auth.currentUser(),
staleTime: Infinity,
})
const profile = useQuery({
queryKey: ["user", me.data?.id],
queryFn: () => getUser(me.data!.id),
enabled: !!me.data,
staleTime: Infinity,
})
return profile.data ?? FALLBACK
}
This expects your users table to use the provider's user id. If you don't
keep a users table yet, build the User straight from me.data (name,
email) and fill the rest with defaults. After sign-out, clear the cache
with queryClient.clear() so the next person doesn't see the last one.
Protect the app pages
The demo lets anyone in. In your app, send signed-out visitors to
/sign-in:
Next.js: create
proxy.tsnext toapp/(Next 16's name for middleware) and redirect when your session cookie is missing:import { NextResponse, type NextRequest } from "next/server" const PUBLIC = [ "/sign-in", "/sign-up", "/forgot-password", "/reset-password", "/two-step", "/maintenance", ] export function proxy(request: NextRequest) { const { pathname } = request.nextUrl if (PUBLIC.some((p) => pathname.startsWith(p))) return if (!request.cookies.has("session")) { const url = new URL("/sign-in", request.url) url.searchParams.set("from", pathname) return NextResponse.redirect(url) } } export const config = { matcher: ["/((?!_next|favicon|icon|.*\\..*).*)"] }Use your provider's cookie name (each guide gives its own
proxy.ts). Check the session properly on the server (in a route handler or server action) before returning private data: the proxy only decides where to send people.Vite: wrap the app routes in a guard. In
src/router.tsx:import { useQuery } from "@tanstack/react-query" import { Navigate, Outlet, useLocation } from "react-router" import { auth } from "@pulze/data" function RequireSignIn() { const { pathname } = useLocation() const me = useQuery({ queryKey: ["me"], queryFn: () => auth.currentUser() }) if (me.isPending) return <FirstLoad /> if (!me.data) return <Navigate to={`/sign-in?from=${pathname}`} replace /> return <Outlet /> }Then make it the parent of the app-layout routes:
{ element: <RequireSignIn />, children: [/* the AppShell route */] }. A Vite app runs entirely in the browser, so your API must check the session on every request too.
Lock screen
The app shell watches for mouse, keyboard, touch and scroll. After
lockAfterMinutes with none, it opens /lock?from=<current page>; unlocking
returns there. People can also lock from the user menu. The timer is per
browser: getLockAfter(), setLockAfter(minutes) and useLockAfter() are
exported from @pulze/layout if you want to store it on the account
instead.
The lock screen is a screen, not a security boundary: anyone who can reach the URL can leave it. Treat it like a screensaver, and keep real checks on the server.
Email templates
Your provider sends the reset, magic-link and invite emails. Keep the wording consistent with the pages:
| Subject | Link goes to | Expires | |
|---|---|---|---|
| Reset | Reset your {name} password | /reset-password?token=… |
30 minutes |
| Magic link | Your {name} sign-in link | your provider's callback | 15 minutes |
| Invite | {person} invited you to {team} | /sign-up?invite=… |
7 days |
If you change an expiry, change the matching sentence on the page ("It works for 30 minutes") too.