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]>
14 lines
779 B
SQL
14 lines
779 B
SQL
CREATE TABLE "two_factor" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"user_id" text NOT NULL,
|
|
"secret" text NOT NULL,
|
|
"backup_codes" text NOT NULL,
|
|
"verified" boolean DEFAULT true NOT NULL,
|
|
"failed_verification_count" integer DEFAULT 0 NOT NULL,
|
|
"locked_until" timestamp with time zone
|
|
);
|
|
--> statement-breakpoint
|
|
ALTER TABLE "user" ADD COLUMN "two_factor_enabled" boolean DEFAULT false NOT NULL;--> statement-breakpoint
|
|
ALTER TABLE "two_factor" ADD CONSTRAINT "two_factor_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
CREATE INDEX "two_factor_user" ON "two_factor" USING btree ("user_id");--> statement-breakpoint
|
|
CREATE INDEX "two_factor_secret" ON "two_factor" USING btree ("secret"); |