auth: build verification link from BASE_URL env var

- Build the verification URL as /api/auth/verify-email?token=xxx&callbackURL=/login
- Pass token from Better Auth callback instead of its built-in url
- Add callbackURL=/login so user lands on login after verifying
This commit is contained in:
NeilClack
2026-07-07 08:59:25 -05:00
parent ba83c48b9e
commit 667ae4e05e
2 changed files with 7 additions and 4 deletions
+2 -2
View File
@@ -13,10 +13,10 @@ export const auth = betterAuth({
}),
emailVerification: {
sendOnSignUp: true,
sendVerificationEmail: async ({ user, url }) => {
sendVerificationEmail: async ({ user, token }) => {
void sendVerificationEmail({
email: user.email,
verificationUrl: url
token
});
}
},
+5 -2
View File
@@ -1,15 +1,18 @@
import { BASE_URL } from '$env/static/private';
import { sendMail } from './resend';
export async function sendVerificationEmail(options: {
email: string;
verificationUrl: string;
token: string;
}) {
const verificationUrl = `${BASE_URL}/api/auth/verify-email?token=${options.token}&callbackURL=/login`;
await sendMail({
to: options.email,
templateId: 'email-verification-email',
data: {
target_email_address: options.email,
verification_link: options.verificationUrl
verification_link: verificationUrl
}
});
}