25 lines
1.0 KiB
TypeScript
25 lines
1.0 KiB
TypeScript
'use server'
|
|
|
|
import mailer from '@/lib/mailer'
|
|
import { AUTH_USER_VERIFICATION_URL } from '@/config/routes'
|
|
import { generateVerificationToken } from '@/lib/tokens'
|
|
import { env } from '@/lib/utils'
|
|
|
|
const sendVerificationEmail = async (email: string, name?: string | null) => {
|
|
const verificationToken = await generateVerificationToken(email)
|
|
const confirmLink: string = [env('SITE_URL'), AUTH_USER_VERIFICATION_URL, verificationToken.token].join('')
|
|
|
|
const { isOk, code, info, error } = await mailer({
|
|
to: name ? { name: name?.toString(), address: verificationToken.email } : 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 } |