feat(auth) : add optional email verification and profile setup
This commit is contained in:
+10
-2
@@ -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
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user