feat: enable account security plugins
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user