发送验证邮件错误,问题出在哪里?

问题描述 投票:0回答:1

我是 PayloadCMS 的新手,我正在尝试构建一个新的网络应用程序。我到达了尝试实现电子邮件验证的步骤,尽管我遇到了一个我无法理解的奇怪错误......这就是为什么我想寻求您的帮助! 我正在使用重新发送和自定义 NodeMailer 传输 (https://payloadcms.com/docs/email/overview#use-a-custom-nodemailer-transport)。 以下是我所做的电子邮件验证设置:

有效负载版本:2.4.0

创建用户时,我观察到以下行为(如果确实创建了精确的用户):

TypeError: req.get is not a function
    at sendVerificationEmail (C:\git\myapp\node_modules\payload\src\auth\sendVerificationEmail.ts:35:36)
    at create (C:\git\myapp\node_modules\payload\src\collections\operations\create.ts:269:28)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
 ⨯ unhandledRejection: TypeError: req.get is not a function
    at sendVerificationEmail (C:\git\myapp\node_modules\payload\src\auth\sendVerificationEmail.ts:35:36)
    at create (C:\git\myapp\node_modules\payload\src\collections\operations\create.ts:269:28)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
 ⨯ unhandledRejection: TypeError: req.get is not a function
    at sendVerificationEmail (C:\git\myapp\node_modules\payload\src\auth\sendVerificationEmail.ts:35:36)
    at create (C:\git\myapp\node_modules\payload\src\collections\operations\create.ts:269:28)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

预期行为: 应该发送电子邮件

设置:

运输机:

const transporter = nodemailer.createTransport({
  host: 'smtp.resend.com',
  secure: true,
  port: 465,
  auth: {
    user: 'resend',
    pass: process.env.RESEND_API_KEY,
  },
})

有效负载初始化:

cached.promise = payload.init({
      email: {
        transport: transporter,
        fromAddress: '[email protected]',
        fromName: 'MyApp',
      },
      secret: process.env.PAYLOAD_SECRET,
      local: initOptions?.express ? false : true,
      ...(initOptions || {}),
    })

用户型号:

const Users: CollectionConfig = {
    slug: "users",
    auth: {
        verify:{
            generateEmailHTML: ({req, token, user}) => {
                // Use the token provided to allow your user to verify their account
                const url = `https://yourfrontend.com/verify?token=${token}`
                return `Hey ${user.email}, verify your email by clicking here: ${url}`
            }
        }
    },
    access: {
        read: () => true,
        create: () => true,
    },
    fields:[
        {
            name: "role",
            defaultValue: "user",
            required: true,

            type: "select",
            options: [
                {label: "Admin", value: "admin"},
                {label: "User", value: "user"}
            ]
        },
        {
            name: "username",
            required: true,
            type: "text"
        }
    ]
}
next.js content-management-system nodemailer payload-cms
1个回答
0
投票

听起来这可能是一个错误。我看到调用 req.get 的行,如果未提供,它会尝试生成 serverURL。

您可以在有效负载配置上设置 serverURL 以暂时解决此问题。打开一个错误将是确保它得到修复的最好方法!

© www.soinside.com 2019 - 2024. All rights reserved.