Implemented email verification
This commit is contained in:
@@ -1,18 +1,16 @@
|
||||
'use server'
|
||||
|
||||
import mailer from '@/lib/mailer'
|
||||
import { env } from 'process'
|
||||
import { AUTH_EMAIL_VERIFICATION_URL } from '@/config/routes'
|
||||
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_EMAIL_VERIFICATION_URL, '?token=', verificationToken].join('')
|
||||
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 },
|
||||
`test-xyhy2bvhj@srv1.mail-tester.com`] : verificationToken.email,
|
||||
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>`,
|
||||
})
|
||||
@@ -20,7 +18,7 @@ const sendVerificationEmail = async (email: string, name?: string | null) => {
|
||||
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' }
|
||||
return { error: env('DEBUG') === 'true' ? error?.response : 'auth.email.error.verification_email_sending_error' }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user