the writing next.js & headless 13 min

Passkey Authentication in Next.js and Supabase: A Working Setup

Supabase passkeys are experimental, Better Auth ships a plugin, and recovery needs a plan before launch. A working Next.js setup for each route.

Line-art browser window linked by a dotted line to a phone with a fingerprint, with a padlock between them

Passkey authentication swaps the password for a key pair: the private half stays on the user's device and the public half sits on your server. In a Next.js app on Supabase you have two realistic routes. Supabase Auth supports passkeys, but its own docs label them experimental. Better Auth ships a passkey plugin built on SimpleWebAuthn, with its defaults written down. Below you get the setup for both, a provider table, the sign-in flow, a plan for lost devices and a rollout checklist. Choosing between providers is a separate question, and the authentication services roundup owns that one.

What a passkey is, and why it beats a password

passkeys.dev puts it plainly: a password is something you remember and type, while a passkey is a secret stored on your devices and used after a biometric check. It lists four properties: intuitive, automatically unique, breach-resistant and phishing-resistant.

The breach point is the one I'd lead with when talking to a client. Your server stores public keys only. Even the servers that sync passkeys between a user's devices never get to view or use the private keys. So a leaked user table gives an attacker nothing to replay.

Phishing resistance comes from the browser and operating system, not from the human. They enforce that a passkey is only used for the service it was created for. A convincing fake login page simply gets no credential.

Is anyone actually using them?

Yes, and the numbers are no longer small. The FIDO Alliance Passkey Index reports, as an average across contributing companies, that 93% of accounts are eligible for passkeys, 36% have one enrolled and 26% of all sign-ins use them. Dashlane's 2026 report counts 2.5 million passkey authentications a month and says 57% of its users hold at least one passkey.

Two caveats. Those are big consumer brands and a password manager's own users, which is not your SaaS. And the sources disagree on how many top sites offer passkeys: Descope, citing FIDO, says 48% of the top 100, while PanicVault estimates approximately 50-60 percent of the top 100 and roughly 20-25 percent of the top 1,000. Different methods, different answers. Both say the same thing: passkeys are mainstream among big sites and patchier further down.

The same Descope piece reports that 87% of organisations still run passwords as part of their auth stack. So you are adding passkeys alongside something, not replacing it on day one.

Browser and device support in 2026

I'm not going to hand you a browser-by-version matrix. None of the primary docs for this stack publish one, and a table I couldn't source would age badly anyway. The honest advice: treat support as a feature-detection problem, not a lookup problem.

What the documentation does give you are the moving parts you need to account for:

  • Platform authenticators (Face ID, Touch ID, Windows Hello) and security keys both work through WebAuthn. Better Auth's defaults allow both, with no authenticatorAttachment set.
  • Cross-device authentication lets a passkey on a phone sign you in on another device. passkeys.dev says it is powered by CTAP using hybrid transport, which in practice means the user scans a code or approves a prompt on the phone.
  • Autofill UI (the WebAuthn spec calls it conditional mediation) shows saved passkeys in the username field when it carries the webauthn autocomplete value.
  • Conditional Create lets you offer to create a passkey right after a successful sign-in with something else. passkeys.dev notes the browser, the OS and the credential manager must all support it.

That last line matters. Three layers each have to agree before a feature works, and you don't control any of them. So detect, then show the button. Hide it otherwise. Never let a missing capability turn into a dead end on the sign-in page.

Test on real hardware. Better Auth also documents emulated authenticators for debugging registration and sign-in without owning a device, which is handy in CI and for the first pass.

Option 1: Supabase Auth

If your users already live in Supabase Auth, this is the shortest path. The catch is in the first paragraph of Supabase's passkey docs: support is experimental, the API may change without notice, and you must opt in explicitly when creating the client. The main Auth overview lists password, magic link, OTP, social sign-in and SSO in its method sentence, and passkeys aren't in it. That fits the experimental label. Read the passkey page again before you ship, and again after any upgrade.

Three-step line-art flow from browser window to phone fingerprint to padlock and server

Client requirements

The minimum versions are @supabase/supabase-js v2.105.0 and later, supabase_flutter v2.15.0 and later, and supabase-swift v2.48.0 and later. In a Next.js project, check your lockfile first, because an older client simply won't have the passkey surface.

The opt-in itself goes in createClient , as auth: { experimental: { passkey: true } }. If you use @supabase/ssr for server rendering, make the same option appear wherever you construct a client that will run a passkey call. Leave one out and you'll chase a confusing difference between browser and server behaviour.

Dashboard or config settings

The docs put the setting under Authentication → Passkeys in the Dashboard. (MakerKit's tutorial says Authentication > Sign In / Providers instead. Dashboards get reorganised, so follow Supabase's own page and look for the passkey toggle if your layout differs.) Turn on the passkey option and fill in three fields:

  • Relying Party Display Name: the human-readable name shown in the passkey prompt.
  • Relying Party ID: the bare domain, such as example.com. No scheme, port or path.
  • Relying Party Origins: a comma-separated list, up to 5. HTTPS is required except for loopback addresses, and each origin's hostname must match or be a subdomain of the Relying Party ID.

The dashboard pre-fills these from your Site URL and project name, so check them if production lives on a different domain.

Now the sharp edge. Changing the Relying Party ID makes every existing passkey unusable for sign-in. Users have to register a new one. Pick the ID with the future in mind: the registrable domain (example.com ) lets app.example.com and www.example.com share credentials, a narrower choice doesn't.

If you manage config in code, the CLI uses [auth.passkey] with enabled = true plus a required [auth.webauthn] section holding rp_display_name , rp_id and rp_origins in supabase/config.toml . The Management API exposes passkey_enabled , webauthn_rp_id , webauthn_rp_display_name and webauthn_rp_origins . If the toggle is off, the server rejects passkey calls with passkey_disabled, which is the first error you'll see on a fresh environment.

Self-hosted

On self-hosted Supabase, GOTRUE_PASSKEY_ENABLED defaults to false. When you enable it, GOTRUE_WEBAUTHN_RP_ID , GOTRUE_WEBAUTHN_RP_DISPLAY_NAME and GOTRUE_WEBAUTHN_RP_ORIGINS are all required. Defaults per the self-hosting page: a maximum of 10 passkeys per user and a WebAuthn challenge expiry of 5m.

The flow, and who can register

Supabase describes each sign-in or registration as a WebAuthn ceremony with three steps. Here it is as a diagram:

StepWhere it runsWhat happens
1. OptionsNext.js client to Supabase AuthThe client asks for a challenge
2. CeremonyBrowser and devicenavigator.credentials.create() or get() prompts for biometrics or a security key
3. VerifySupabase AuthThe signed response is checked; a new credential is stored, or a session is issued

Two rules shape your UI. Registration needs an existing, confirmed, non-anonymous user, so the account must exist first, by email or whichever method you already use. Sign-in uses discoverable credentials, so the user doesn't type an email, phone or username: the authenticator resolves the account. It works for anyone who has registered a passkey, as long as their email or phone is confirmed and the account isn't banned.

That gives you the natural Next.js shape. Sign up with your current method. Confirm. Then offer "add a passkey" in account settings or right after the first sign-in. On the sign-in page, a single passkey button needs no form fields at all.

MakerKit's Supabase kit sets NEXT_PUBLIC_AUTH_PASSKEY=true to show the UI and says no migration is needed because Supabase Auth stores the credentials. Useful as a reference if you're deciding how much UI to build yourself.

Option 2: Better Auth passkey plugin

If you want the credentials in your own database and a stable, documented surface, the Better Auth passkey plugin is the stronger route. It's powered by SimpleWebAuthn and the docs describe it as supported by WebAuthn and FIDO2 standards. MakerKit says its Drizzle and Prisma kits use @better-auth/passkey, registered on server and client, with a build-time flag and a database migration, and that it was tested with Next.js 16. That's their claim, with their stack.

The setup has four moves:

  1. Add the plugin to the plugins option of your auth instance, and its client counterpart on the client.
  2. Run the migration or generate the schema. The plugin needs a passkey table.
  3. Set rpID , rpName and origin.
  4. Add the register and sign-in calls to your UI.

Getting rpID right

The rpID can be formed by discarding zero or more labels from the left of the effective domain until you hit an effective TLD. So www.example.com can use www.example.com or example.com , but not com . localhost is fine for local development. Same lesson as Supabase: choose it once.

Defaults worth knowing

  • residentKey and userVerification both default to preferred.
  • authenticatorAttachment is unset, so platform and cross-platform passkeys are both allowed, with platform preferred.
  • The challenge cookie is named better-auth-passkey by default.
  • Passkeys without a name default to the user's email address or user ID.

The calls

To register, make sure the user is authenticated and call passkey.addPasskey , optionally passing a name or an authenticatorAttachment . To sign in, call signIn.passkey . List a user's passkeys with passkey.listUserPasskeys , rename with an update call that takes id and name , and remove with passkey.delete . One gotcha: setting throw: true in fetch options has no effect on the register and sign-in responses. They always return a data object containing the error, so check it.

Conditional UI

Add autocomplete with the webauthn value to at least one input, and make webauthn the last entry of that attribute (so username webauthn , not webauthn username ). Then, when the component mounts, call authClient.signIn.passkey with autoFill: true. The plugin checks for browser support first. Some browsers also want the user to interact with the field before the prompt shows.

Passkey-first sign-up

Set registration.requireSession to false and registration can start with no session. You pass an opaque context to the options endpoint and it is forwarded to resolveUser . If you don't want a user row created before the ceremony succeeds, create or load the user in registration.afterVerification and return its userId. That's the one to use if you want truly passwordless sign-up, which Supabase's rule (confirmed user first) doesn't allow.

Naming passkeys

Each row stores an aaguid , the identifier of the authenticator model. Resolve a friendly label at render time. Apple devices report an all-zero AAGUID under the default attestation: "none" flow, and that resolves to nothing, so keep a fallback label like "Passkey added on [date]".

Managed providers

There is a third path: let someone else run the ceremony. I've compared the four names you asked about below. The effort column is my read, not a measurement, and I've left Clerk and Auth0 as "check their docs" because I'm not putting a status in your hands that I can't point to a source for.

ProviderPasskey statusSetup effort (my read)Notes
Supabase AuthExperimental; explicit client opt-in; needs supabase-js v2.105.0 or laterLow to moderate: toggle, three relying party fields, SDK checkCredentials stored by Supabase Auth; API may change
Better AuthPlugin, powered by SimpleWebAuthnModerate: plugin on both sides, a passkey table, rpID and origin configConditional UI, passkey-first registration, extensions documented
ClerkCheck Clerk's current docsNot assessed hereCompare in the roundup
Auth0Check Auth0's current docsNot assessed hereCompare in the roundup

If you're on Supabase for the database but want passkeys from another provider, there's a documented bridge. Descope's tutorial uses its Next.js SDK for the session, then generates a Supabase-approved JWT with jose and the Supabase JWT secret, embedding the Descope user ID. Their walkthrough shows the pattern. It works, but you now own a token-minting step, and anything that signs JWTs with your secret deserves a careful review. For provider-level comparisons beyond passkeys, the authentication section is the place to start.

Fallbacks and account recovery

This is where passkey projects get hard, and it isn't the WebAuthn part. A passkey proves the user has a device (or a password manager) and can open it. What happens when they don't?

Start with the principle: keep at least one non-passkey path until you have a good reason to remove it. On Supabase that's easy, because passkey registration already requires a confirmed account from another method. Email magic link or OTP remains your recovery route. On Better Auth, if you go passkey-first, you have to build recovery yourself, so decide before launch.

A few design choices help:

  • Encourage more than one passkey. Supabase's self-hosted default allows up to 10 per user, so there's room. Prompt for a second after the first.
  • Let users name and remove passkeys. Better Auth's list, rename and delete calls make a decent settings page easy. Use the AAGUID label where it resolves, and a date where it doesn't.
  • Use cross-device sign-in as the first rescue. A phone passkey can sign in on a new laptop via hybrid transport, so the user may not be locked out at all.
  • Offer passkey creation after a successful fallback sign-in. That's Conditional Create territory, where the platform supports it. Someone who just recovered their account is the most motivated user you'll ever have.

One more trap: domain changes. In both stacks the relying party ID binds the credential to the domain. A rebrand or a move from app.example.com to a different registrable domain strands every passkey. Plan the domain before you enrol anyone.

If the recovery policy is more than a settings toggle for you (regulated data, support teams who need to verify identity by hand), that's custom workflow territory, and bespoke web development is where we'd design it with you.

Rollout checklist

Here's the order I'd work in. It applies to either stack.

  1. Pick the relying party ID and origins. Registrable domain, HTTPS everywhere except loopback, no more than 5 origins on Supabase. Write the decision down, since changing it breaks every existing passkey.
  2. Check versions. For Supabase, @supabase/supabase-js v2.105.0 or later. For Better Auth, the plugin installed on server and client, plus the migration applied.
  3. Enable in every environment. Dashboard toggle or config.toml for Supabase (or GOTRUE_PASSKEY_ENABLED plus the three WebAuthn variables when self-hosted). A passkey_disabled error means one environment was missed.
  4. Opt in on the client. The experimental.passkey option in createClient, wherever a client is built.
  5. Add "create a passkey" to account settings. Then add a post-sign-in prompt once settings work.
  6. Add the sign-in button and, if you can, autofill. Feature-detect first. Put webauthn last in autocomplete.
  7. Build the management screen. List, name, delete. Include a fallback label for authenticators that report nothing.
  8. Test on real devices. Phone, laptop, security key, a second device through cross-device sign-in, and at least one password manager. Use emulated authenticators for automated runs.
  9. Keep the fallback live. Email or OTP stays available until your recovery story is tested.
  10. Watch the Supabase page. If you're on the experimental API, re-read the passkey docs before each client upgrade.

One optional step: track the share of sign-ins that use passkeys. The FIDO figure (26% of sign-ins at large contributing companies) is a ceiling to be sceptical of, not a target for a small app. Your own trend is the useful number.

FAQ

Do passkeys replace two-factor authentication?

Not automatically. A passkey is a single credential that combines possession with a biometric or PIN check on the device. passkeys.dev notes its current guidance targets sites moving from password-only or password plus OTP flows, and that guidance for higher-assurance scenarios is still to come. If you have strict compliance needs, check what your auditor accepts before dropping a second factor.

Can I use passkeys on localhost during development?

Yes. Better Auth says localhost is fine as an rpID for local development. Supabase allows loopback addresses ( localhost , 127.0.0.1 and [::1]) as origins without HTTPS. Anywhere else, plan for HTTPS.

Will existing users see a passkey prompt without doing anything?

No. Users must register one first. On Supabase that means an existing, confirmed, non-anonymous account. On Better Auth you either require a session or enable passkey-first registration with registration.requireSession set to false.

Does Supabase store the private key?

No. The private key stays on the user's device or in their password manager. Supabase registers the matching public key and uses it to verify later sign-ins. That's the same model passkeys.dev describes for any relying party server.

Should I wait until Supabase passkeys leave experimental status?

That depends on how much API churn you can absorb. The docs warn the API may change without notice, so a small team that can re-test on each upgrade can ship now. If a change would be expensive, Better Auth's documented plugin is the steadier option.

The sharpest caveat is the relying party ID: change it after launch and every existing passkey stops working for sign-in, on either stack. Everything else, from the experimental flag to recovery design, is easier to fix than that one decision.

this post in the tree

Need this done, not just read?

Discuss your website Book 30 minutes