27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
'use server'
|
|
|
|
import mailer from '@/lib/mailer'
|
|
import { env } from 'process'
|
|
import { AUTH_EMAIL_VERIFICATION_URL } from '@/config/routes'
|
|
import { generateVerificationToken } from '@/lib/tokens'
|
|
|
|
const sendVerificationEmail = async (email: string, name?: string | null) => {
|
|
const verificationToken = await generateVerificationToken(email)
|
|
const confirmLink: string = [env.SITE_URL, AUTH_EMAIL_VERIFICATION_URL, '?token=', verificationToken].join('')
|
|
|
|
const { isOk, code, info, error } = await mailer({
|
|
to: name ? [
|
|
{ name: name?.toString(), address: verificationToken.email },
|
|
`test-xyhy2bvhj@srv1.mail-tester.com`] : verificationToken.email,
|
|
subject: 'Complete email verification for A-Naklejka',
|
|
html: `<p>Click <a href="${confirmLink}">here</a> to confirm email</p>`,
|
|
})
|
|
|
|
if (isOk) {
|
|
return { success: code === 250 ? 'auth.email.success.confirmation_email_sent' : info?.response }
|
|
} else {
|
|
return { error: env.DEBUG === 'true' ? error?.response : 'auth.email.error.verification_email_sending_error' }
|
|
}
|
|
}
|
|
|
|
export { sendVerificationEmail } |