`autoSignInAfterVerification` is not working for me.

My config looks like -
emailVerification: {
autoSignInAfterVerification: true,
callbackURL: `${bindings.BETTER_AUTH_URL}/onboarding`,
sendVerificationEmail: async (data: { user: User; url: string }) => {
await sendEmail({
apiKey: bindings.RESEND_API_KEY,
to: data.user.email,
from: bindings.RESEND_SENDER_EMAIL,
subject: "Verify your email address",

text: `Click the link to verify your email: ${data.url}`,
});
},
},
emailVerification: {
autoSignInAfterVerification: true,
callbackURL: `${bindings.BETTER_AUTH_URL}/onboarding`,
sendVerificationEmail: async (data: { user: User; url: string }) => {
await sendEmail({
apiKey: bindings.RESEND_API_KEY,
to: data.user.email,
from: bindings.RESEND_SENDER_EMAIL,
subject: "Verify your email address",

text: `Click the link to verify your email: ${data.url}`,
});
},
},
When I click on link in URL, my email verification does get finished correctly, but I am not signed in . I have to go through sign in screen for that. The url I get is pages.dev/api/auth/verify-email?token=some-long-token&callbackURL=/ How can I customize callbackURL ? and how can I safely land user to that url as a signed in user? I am on very latest version 1.0.20
5 Replies
anand248
anand248OP4mo ago
Thanks for help. Le me know if you need any other detail.
bekacru
bekacru4mo ago
to change the callback url before you send them the url you can change the callbackURL query param. And for the sign-in check on the redirect if it tries to set any cookies
anand248
anand248OP4mo ago
Thanks. This
const url = data.url.replace(
"&callbackURL=/",
"&callbackURL=/onboarding"
);
const url = data.url.replace(
"&callbackURL=/",
"&callbackURL=/onboarding"
);
get me going. It also solved the sign in after verification issue. (One another issue, I am experiencing, is the verification emails do not trigger instantly until user try to sign in again and gets the message that email is not verified.).
bekacru
bekacru4mo ago
you're suggesting verification emails should be triggered on signIn?
anand248
anand248OP4mo ago
verification email should trigger instantly on sign up. But it is triggering late, sometime, until user attempts a sign in. Invitation email does get trigger instantly. Either some issue in the code which trigger verification email or my email sender (Resend) is causing delay somewhere.

Did you find this page helpful?