feat(auth) : add optional email verification and profile setup
CI / Verify (push) Failing after 57s
CI / Build immutable images and deploy (push) Skipped

This commit is contained in:
2026-10-08 18:46:04 +07:00 Unverified
parent 01f44688fb
commit da5de3fa8c
8 changed files with 111 additions and 16 deletions
+10 -2
View File
@@ -74,13 +74,21 @@ describe("actual administrator session boundary", () => {
expect(await getCustomerSession()).toMatchObject({ user: { id: "user-1" } });
expect(await getAdminSession()).toMatchObject({ user: { id: "user-1" } });
});
it("requires verification and sends auth links from the configured sender", async () => {
it("allows an unverified customer session but rejects administrator access", async () => {
mocks.session.mockResolvedValue({ user: { id: "user-1", email: "[email protected]",
emailVerified: false, role: "admin" }, session: { id: "guide-session" } });
const { getAdminSession, getCustomerSession, requireAdmin } = await import("./server");
expect(await getCustomerSession()).toMatchObject({ user: { id: "user-1", emailVerified: false } });
expect(await getAdminSession()).toBeNull();
await expect(requireAdmin()).rejects.toMatchObject({ status: 401 });
});
it("allows unverified sign-in and sends auth links from the configured sender", async () => {
testEnv.RESEND_API_KEY = "test-key";
const fetchMock = vi.spyOn(globalThis, "fetch").mockResolvedValue(new Response(null, { status: 200 }));
try {
(await import("./server")).getAuth();
const options = mocks.auth.mock.calls.at(-1)![0];
expect(options.emailAndPassword.requireEmailVerification).toBe(true);
expect(options.emailAndPassword).toMatchObject({ requireEmailVerification: false, autoSignIn: true });
expect(options.emailAndPassword.resetPasswordTokenExpiresIn).toBe(3600);
expect(options.emailVerification).toMatchObject({
sendOnSignUp: false, autoSignInAfterVerification: true, expiresIn: 3600,
+2 -1
View File
@@ -53,7 +53,8 @@ function createAuth() {
secret: required("BETTER_AUTH_SECRET"),
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
requireEmailVerification: false,
autoSignIn: true,
minPasswordLength: 6,
maxPasswordLength: 128,
resetPasswordTokenExpiresIn: 3600,