sendVerificationRequest(Next Auth)问题

qc6wkl3g  于 2023-06-29  发布在  其他
关注(0)|答案(1)|浏览(67)

我试图发送一个登录电子邮件后,进入电子邮件使用nextauth,发送邮件工作正常,没有nodemailer和把手,但它不工作,一旦我已经实现了他们。当我单击signIn时,编译器不会输入sendVerificationRequest,也不会抛出任何错误。my [... nextauth] file:

import NextAuth from "next-auth/next";
import EmailProvider from "next-auth/providers/email";
import nodemailer from 'nodemailer'
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { PrismaClient } from "@prisma/client";
import Handlebars from 'handlebars'
import { readFileSync } from 'fs'
import path from "path";

const prisma = new PrismaClient()

const transporter = nodemailer.createTransport({
    host: process.env.EMAIL_SERVER_HOST,
    port: process.env.EMAIL_SERVER_PORT,
    auth: {
        user: process.env.EMAIL_SERVER_USER,
        pass: process.env.EMAIL_SERVER_PASSWORD,
    },
    secure: true,
});

const emailsDir = path.resolve(process.cwd(), 'emails');

const sendVerificationRequest = async ({ identifier, url }) => {
    console.log('send verification req entered')
    const emailFile = readFileSync(path.join(emailsDir, 'confirm-email.html'), {
        encoding: 'utf8',
    });
    const emailTemplate = Handlebars.compile(emailFile);
    const result = await transporter.sendMail({
        from: `"✨ FreiDrops" ${process.env.EMAIL_FROM}`,
        to: identifier,
        subject: 'Your sign-in link for FreiDrops',
        html: emailTemplate({
            base_url: process.env.NEXTAUTH_URL,
            signin_url: url,
            email: identifier,
        }),
    });
    const failed = result.rejected.concat(result.pending).filter(Boolean)
    if (failed.length) {
        throw new Error(`Email(s) (${failed.join(", ")}) could not be sent`)
    }
};
export default NextAuth({
    pages: {
        signIn: '/',
        signOut: '/',
        error: '/',
        verifyRequest: '/'
    },
    providers: [
        EmailProvider({
            maxAge: 10 * 60, // Magic links are valid for 10min!!
            sendVerificationRequest,
        })
    ],
    adapter: PrismaAdapter(prisma)
})

我做错什么了吗

ocebsuys

ocebsuys1#

出于某种原因,我可以通过将代码更改为:

sendVerificationRequest(params) {
  void sendVerificationRequest(params);
},

相关问题