/be:authfrom Backend Skills
Authentication with Firebase Auth and Next.js — sign-in on the client, an httpOnly session cookie only the API mints, server-first password sign-in behind a lockout, account linking, auth email the API sends itself, password rules and breached-credential checks, optional customer MFA, session lifetimes and renewal, sign-out that ends the session on the server, operator sessions with a second factor, API keys, and where the check sits in a Next.js app. Use when building or reviewing sign-in, sessions, sign-out, auth email or a signed-in gate.
Ships in Backend Skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Firebase Auth proves who someone is; the API turns that proof into a session and checks it on every request. The browser signs in with the Firebase web SDK, trades the fresh ID token for an httpOnly session cookie the API mints, and from then on every server read and action carries that cookie. The client SDK's own state never decides who is signed in: a Server Component can't see it, and a token held in JavaScript is readable by any script on the page.
Before applying this skill, read the project's root AGENTS.md, the AGENTS.md closest to the files in question, and any doc they link for this skill's topic. Names, values and choices — budgets, tiers, tokens, voice, paths — come from those files, never from this skill.
@timonwa/firebase-hooks/auth; the project's own composites wrap them in its hooks package. Client persistence is off (inMemoryPersistence), and once the cookie is set the SDK signs out — Firebase's own pattern, so the cookie is the only session.rate-limiting), checks the password through Identity Toolkit, and answers a custom token the client signs in with. Signing in with the password in the browser skips the lockout, the alerts and the audit entry.auth_time), refuses older ones with 401, and sets the cookie. The session route is a mutation, so the proxy's origin check covers it against CSRF (backend-security).?redirect= is followed only when it's a path on this site (safeRedirectPath from @timonwa/app-utilities); anything else is an open redirect.auth/account-exists-with-different-credential: answer by asking them to sign in the way they did before, then link the new provider to that account (linkWithCredential) — never create a second account.The flow-by-flow table — which layer drives each, and the Identity Toolkit calls the Admin SDK lacks — is references/flows.md.
The API sends every auth email — verification, its resend, password reset, the sign-in link — through the project's own email provider, never the Firebase client or Firebase's templates. The Admin SDK generates each link (generateEmailVerificationLink, generatePasswordResetLink, generateSignInWithEmailLink) and the API points it at the app that asked, so the send is rate-limited, the answer never reveals whether an address is known, and the mail matches the product (transactional-email).
Email verification is a wall. The API refuses an unverified account (403) on every route except the few it needs to finish verifying, kept as an allowlist with a test; every signed-in gate redirects it to the verify page. Opening the link calls the session refresh so the cookie's email_verified changes.
From NIST SP 800-63B and OWASP:
HttpOnly, Secure, SameSite=Lax, Path=/, a Max-Age equal to the session's life. Name it __Host-… with no Domain when one origin uses it; when it must span the product's subdomains, set Domain to the tier's parent domain and name it __Secure-…. Local development on localhost keeps both, since Chrome and Firefox treat it as secure. (Classic Firebase Hosting forwards only a cookie named __session; App Hosting has no such limit.)Clear-Site-Data: "cache", "storage", so the browser drops cached pages and stored data from the session; not "cookies", which would also clear the device cookie.revokeRefreshTokens) and deletes every session record; verification passes checkRevoked: true, so every cookie minted before is refused.The admin panel is a higher assurance level (NIST AAL2):
redis); an unreachable clock is a 401.requireSession guard accepts a Bearer ID token or the session cookie, verifies with revocation checked, refuses an unverified email outside the allowlist, and returns the token and the actor. Guards for permissions build on it (access-control).token.uid), never from a body, query or header.For a public API, customers create keys for their own scripts and integrations; what a key may do is access-control's.
<product>_live_…, <product>_test_…) and a short checksum at the end, so secret scanners and people can recognise one and a scanner can tell a real key from a lookalike without calling the API. A public product registers the format with GitHub's secret-scanning partner programme, so a leaked key is reported to it.Authorization: Bearer <key>, never in a URL, and accepted only on the routes that take keys; a key never mints a session.Next.js's own rule: the real check sits beside the data, because layouts don't re-render on navigation and don't stop their child segments rendering. Here the data is the API, which checks every request — so the app's checks are for the experience:
<Suspense> and redirects a signed-out, unverified or unfinished account before the shell renders. Never at the root layout: it would hold every page, including public ones, behind a request.getCurrentUser, with requireAuth and requireGuest beside it) that sends the cookie to the API's profile route. It's cached with "use cache: private" and a tag, which every profile change and sign-in or out expires (nextjs). The helper never imports firebase-admin.<Suspense>; take identity from the token.Permissions access-control · lockout and auth rate tiers rate-limiting · the route around the guard api-architecture · CSRF and server threats backend-security · the idle clock redis · auth email delivery transactional-email · caching the current user nextjs · the sign-in UI react.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub timonwa/engineering-skills --plugin be22 skills in this plugin
/access-controlAccess control for a Next.js API on Firebase — roles, relationships and attributes (RBAC, ReBAC, ABAC) behind permission verbs and one pure can(); guards as the only gate, 404 before 403; tenant scoping; invitations; escalation limits; two-person approval and access reviews; stale claims; API-key scopes; share links and passcodes; where plan and flag checks sit; UI gates that only hide; and tests. Use when adding a permission, role, guarded route, API key, share link, or a control only some people see./access-control-auditManually invoked. Access-control audit — guards on every route and Server Action (BFLA), 404 before 403 and tenant scoping (BOLA), allowlisted writes and projected reads (BOPLA), verbs never role names, roles that add up, escalation and invitations, claims and revocation, sessions and sign-in, API keys and share links, the plan and flag order, UI gates, data rules and the tests. Verifies each finding and writes a prioritised report./api-architectureHow an API route is built in a Next.js API — the fixed order of rate limit, authorise, validate, delegate, audit, respond; thin routes over services; the response envelope and typed errors; caching headers; concurrent edits; long-running work; cursor pagination and allowlisted sorts; resource paths, versions, deprecation and state-transition sub-routes; and what every new route ships with. Cron, webhooks and audit logs are references. Use when adding, changing or reviewing a route handler or the API layer's structure.Other plugins' skills for the same job