Better Auth's twoFactor plugin: an authenticator app (TOTP) with 10 backup codes. Turning it on, making new backup codes and turning it off are on the account page, and signing in asks for a code once it's on. Sensitive permissions (product:remove, person:ban, person:role, settings:edit, catalog:suspend, ...) answer 403 two_factor_required without it, API tokens included; the console reminds people who need it. Better Auth's own admin endpoints are closed (404). Co-Authored-By: Claude Opus 5.5 <[email protected]>
11 lines
566 B
TypeScript
11 lines
566 B
TypeScript
// Better Auth in the browser: sign-up, sign-in (with a two-factor code when it's on), sign-out, and two-factor setup.
|
|
// Its requests go to /api/auth on this site, which Next rewrites to the API, so the session cookie is set for this site.
|
|
"use client";
|
|
import { createAuthClient } from "better-auth/react";
|
|
import { twoFactorClient, usernameClient } from "better-auth/client/plugins";
|
|
|
|
export const authClient = createAuthClient({
|
|
baseURL: typeof window === "undefined" ? undefined : window.location.origin,
|
|
plugins: [usernameClient(), twoFactorClient()],
|
|
});
|