diff --git a/src/plugins.ts b/src/plugins.ts index b14ef3f..42b6e36 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -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) { diff --git a/tests/auth-config.test.ts b/tests/auth-config.test.ts index de5cdaf..9892a2d 100644 --- a/tests/auth-config.test.ts +++ b/tests/auth-config.test.ts @@ -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", () => {