mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-31 11:26:42 -05:00
chore: add sign-in after verification test
This commit is contained in:
@@ -63,4 +63,34 @@ describe("Email Verification", async () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("should sign after verification", async () => {
|
||||
const { testUser, signInWithUser, client } = await getTestInstance({
|
||||
emailAndPassword: {
|
||||
enabled: true,
|
||||
requireEmailVerification: true,
|
||||
},
|
||||
emailVerification: {
|
||||
async sendVerificationEmail({ user, url, token: _token }) {
|
||||
token = _token;
|
||||
mockSendEmail(user.email, url);
|
||||
},
|
||||
autoSignInAfterVerification: true,
|
||||
},
|
||||
});
|
||||
await signInWithUser(testUser.email, testUser.password);
|
||||
|
||||
let sessionToken = "";
|
||||
const res = await client.verifyEmail({
|
||||
query: {
|
||||
token,
|
||||
},
|
||||
fetchOptions: {
|
||||
onSuccess(context) {
|
||||
sessionToken = context.response.headers.get("set-auth-token") || "";
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(sessionToken.length).toBeGreaterThan(10);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -272,7 +272,6 @@ export const verifyEmail = createAuthEndpoint(
|
||||
await ctx.context.internalAdapter.updateUserByEmail(parsed.email, {
|
||||
emailVerified: true,
|
||||
});
|
||||
|
||||
if (ctx.context.options.emailVerification?.autoSignInAfterVerification) {
|
||||
const currentSession = await getSessionFromCtx(ctx);
|
||||
if (!currentSession) {
|
||||
|
||||
@@ -404,7 +404,6 @@ export const signInEmail = createAuthEndpoint(
|
||||
},
|
||||
ctx.request,
|
||||
);
|
||||
ctx.context.logger.error("Email not verified", { email });
|
||||
throw new APIError("FORBIDDEN", {
|
||||
message: BASE_ERROR_CODES.EMAIL_NOT_VERIFIED,
|
||||
});
|
||||
|
||||
@@ -68,7 +68,7 @@ const formatMessage = (level: LogLevel, message: string): string => {
|
||||
const timestamp = new Date().toISOString();
|
||||
return `${colors.dim}${timestamp}${colors.reset} ${
|
||||
levelColors[level]
|
||||
}${level.toUpperCase()}${colors.reset} ${colors.bright}Better Auth${
|
||||
}${level.toUpperCase()}${colors.reset} ${colors.bright}[Better Auth]:${
|
||||
colors.reset
|
||||
} ${message}`;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user