Authentication
Scaffold Niral authentication with passwords, WebAuthn passkeys, TOTP two-factor authentication and OAuth. Protect routes and manage signed-in users.
On this page 3 sections
niral add auth
Scaffolds working pages into your project (you own the code): /auth/register, /auth/login, /auth/account and an OAuth callback route — with passwords (scrypt), passkeys (WebAuthn), TOTP 2FA, login rate limiting, and session rotation. Zero dependencies — Niral implements WebAuthn, CBOR and TOTP itself.
Guarding routes
<server auth> <!-- signed-in users only -->
<server auth="admin"> <!-- role required -->
Guards run before any user code — pages redirect to login (with ?next=), RPC and form actions return 401/403. Layout guards protect whole sections.
The user, everywhere
props.user is available on every page; user() in every server block.
export async function load() {
return { orders: await ordersFor(user().email) }
}
OAuth
Set NIRAL_OAUTH_GOOGLE_ID / _SECRET (also github, microsoft, linkedin) and "Continue with Google" appears on the scaffolded login page. PKCE + state on every provider.