feat: enable account security plugins

This commit is contained in:
2026-06-10 02:42:05 -07:00
parent 2f7cf3884b
commit f9f3af9e1d
2 changed files with 25 additions and 1 deletions

View File

@@ -1,6 +1,16 @@
import { passkey } from "@better-auth/passkey";
import type { BetterAuthPlugin } from "better-auth";
import { captcha, emailOTP, genericOAuth, haveIBeenPwned, openAPI } from "better-auth/plugins";
import {
admin,
captcha,
emailOTP,
genericOAuth,
haveIBeenPwned,
lastLoginMethod,
multiSession,
openAPI,
twoFactor,
} from "better-auth/plugins";
import { buildAuthEmail, sendEmail } from "./email";
import type { Env } from "./env";
import { createGenericOAuthProviders } from "./oauth";
@@ -22,6 +32,10 @@ export function createAuthPlugins(env: Env): BetterAuthPlugin[] {
await sendEmail(env, buildAuthEmail({ kind: "email-otp", to: email, otp }));
},
}),
twoFactor(),
multiSession({ maximumSessions: 10 }),
lastLoginMethod({ storeInDatabase: true }),
admin(),
];
if (env.CAPTCHA_PROVIDER === "cloudflare-turnstile" && env.CAPTCHA_SECRET_KEY) {

View File

@@ -99,6 +99,16 @@ describe("auth plugins", () => {
});
expect(plugins.map((plugin) => plugin.id)).toContain("email-otp");
});
it("enables account security and admin plugins", () => {
const plugins = createAuthPlugins({
BETTER_AUTH_URL: "http://localhost:8788",
TRUSTED_ORIGINS: "http://localhost:8787",
});
expect(plugins.map((plugin) => plugin.id)).toEqual(
expect.arrayContaining(["two-factor", "multi-session", "last-login-method", "admin"]),
);
});
});
describe("oauth config", () => {