2023-03-15 08:35:16 +01:00
|
|
|
import { sendMagicLinkEmail } from '@typebot.io/emails'
|
2023-03-13 11:20:28 +01:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
identifier: string
|
2023-03-28 07:54:20 +02:00
|
|
|
token: string
|
2023-03-13 11:20:28 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-28 07:54:20 +02:00
|
|
|
export const sendVerificationRequest = async ({ identifier, token }: Props) => {
|
2023-03-13 11:20:28 +01:00
|
|
|
try {
|
2023-03-28 07:54:20 +02:00
|
|
|
const url = `${
|
|
|
|
|
process.env.NEXTAUTH_URL
|
|
|
|
|
}/api/auth/callback/email?${new URLSearchParams({
|
|
|
|
|
email: identifier,
|
|
|
|
|
token,
|
2023-03-28 09:51:01 +02:00
|
|
|
callbackUrl: `${process.env.NEXTAUTH_URL}/signin`,
|
2023-03-28 07:54:20 +02:00
|
|
|
}).toString()}`
|
2023-03-13 11:20:28 +01:00
|
|
|
await sendMagicLinkEmail({ url, to: identifier })
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw new Error(`Email(s) could not be sent`)
|
|
|
|
|
}
|
|
|
|
|
}
|