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:
+2
-2
@@ -13,10 +13,10 @@ export const auth = betterAuth({
|
|||||||
}),
|
}),
|
||||||
emailVerification: {
|
emailVerification: {
|
||||||
sendOnSignUp: true,
|
sendOnSignUp: true,
|
||||||
sendVerificationEmail: async ({ user, url }) => {
|
sendVerificationEmail: async ({ user, token }) => {
|
||||||
void sendVerificationEmail({
|
void sendVerificationEmail({
|
||||||
email: user.email,
|
email: user.email,
|
||||||
verificationUrl: url
|
token
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
|
import { BASE_URL } from '$env/static/private';
|
||||||
import { sendMail } from './resend';
|
import { sendMail } from './resend';
|
||||||
|
|
||||||
export async function sendVerificationEmail(options: {
|
export async function sendVerificationEmail(options: {
|
||||||
email: string;
|
email: string;
|
||||||
verificationUrl: string;
|
token: string;
|
||||||
}) {
|
}) {
|
||||||
|
const verificationUrl = `${BASE_URL}/api/auth/verify-email?token=${options.token}&callbackURL=/login`;
|
||||||
|
|
||||||
await sendMail({
|
await sendMail({
|
||||||
to: options.email,
|
to: options.email,
|
||||||
templateId: 'email-verification-email',
|
templateId: 'email-verification-email',
|
||||||
data: {
|
data: {
|
||||||
target_email_address: options.email,
|
target_email_address: options.email,
|
||||||
verification_link: options.verificationUrl
|
verification_link: verificationUrl
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user