我设法创建了一个SendGrid帐户,并安装了Strapi Sendgrid NPM软件包,以使Strapi自动发送带有链接的确认电子邮件以确认为新用户注册。
但是我注意到,在电子邮件中,确认链接显示:
http://0.0.0.0:1337/api/auth/email-confirmation?confirmation=d48f20893fed7a1b0854b12996d409c31f3c7f9c
第一个问题是0.0.0.0的IP地址,这不是我的strapi的正确IP地址。...让我们说我的IP地址是1.1.1.1。 ...
发送确认电子邮件时,如何使URL指向正确的IP地址?我似乎找不到在Stapi后端更改的字段以更改URL ....
其次,当我将0.0.0.0更改为正确的IP地址并保持其余的相同时。似乎不起作用,我的用户在Strapi后端中的电子邮件无法确认电子邮件本身。
我如何确保Strapi的确认链接实际上可以确认并验证新用户的电子邮件???
=============================================
i 已将我的config/server.js文件更改为以下内容:
module.exports = ({ env }) => ({
host: env('HOST', 'MY_IP_ADDRESS'),
port: env.int('PORT', 1337),
app: {
keys: env.array('APP_KEYS'),
},
});
因此,我现在收到的确认链接显示了以下内容:
MY_IP_ADDRESS:1337/api/auth/email-confirmation?confirmation=395d52db4863d7617427f65ae7010ece32d2b2da
但是,当我将链接复制并粘贴到浏览器时(与单击它相同)时,我会得到:
{"data":null,"error":{"status":500,"name":"InternalServerError","message":"Internal Server Error"}}
当我做 PM2日志
它显示以下错误:
0 | strapi | [2022-05-20 17:25:35.196]错误:未定义的属性级别
操作员确认token 0 | strapi |错误:未定义的属性
级别运算符确认token 0 | strapi |在
processAttribute Where
(/home/bliss/strapi/node_modules/@strapi/database/lib/query/helpers/where.js:82:13)
0 | strapi |在过程中
(/home/bliss/strapi/node_modules/@strapi/database/lib/query/helpers/where.js:176:36)
0 | strapi |在
/home/bliss/strapi/node_modules/@strapi/database/lib/query/helpers/where.js:104:29
0 | strapi |在array.map()0 | strapi |在
object.processwhere
(/home/bliss/strapi/node_modules/@strapi/database/lib/query/helpers/where.js:104:18)
0 | strapi |在object..processstate
(/home/bliss/strapi/node_modules/@strapi/database/lib/query/query-builder.js:234:29)
0 | strapi |在object.getKnexquery
(/home/bliss/strapi/node_modules/@strapi/database/lib/query/query-builder.js:271:12)
0 | strapi |在object.ecute
(/home/bliss/strapi/node_modules/@strapi/database/lib/query/query-builder.js:352:25)
0 | strapi |在object.findone
(/home/bliss/strapi/node_modules/@strapi/database/lib/entity-manager.js:121:10)
0 | strapi |在processTickSandlejections
(节点:内部/process/task_queues:96:5)0 | strapi |在异步
object.findone
(/home/bliss/strapi/node_modules/@strapi/strapi/strapi/lib/services/entity-service/index.js:67:20)
0 | strapi |在异步对象。EmailConfircation
(/home/bliss/strapi/node_modules/@strapi/plugin-users-permissions/server/server/controllers/auth.js:381:18)
0 | strapi |在Async returnbodymiddleware上
(/home/bliss/strapi/node_modules/@strapi/strapi/strapi/lib/services/server/server/compose-endpoint.js:52:18)0 | strapi |在异步策略Middleware
(/home/bliss/strapi/node_modules/@strapi/strapi/lib/services/server/policy.js:24:5)
0 | strapi |在异步服务
(/home/bliss/strapi/node_modules/koa-static/index.js:59:5)0 | strapi |
在Async returnbodymiddleware上
(/home/bliss/strapi/node_modules/@strapi/strapi/strapi/lib/services/server/server/compose-endpoint.js:52:18)0 | strapi |在异步策略Middleware
(/home/bliss/strapi/node_modules/@strapi/strapi/lib/services/server/policy.js:24:5)
0 | strapi |在异步
/home/bliss/strapi/node_modules/@strapi/strapi/lib/middlewares/body.js:51:9
0 | strapi |在异步
/home/bliss/strapi/node_modules/@strapi/strapi/lib/middlewares/logger.js:22:5
0 | strapi |在异步
/home/bliss/strapi/node_modules/@strapi/strapi/lib/middlewares/powered-by.js:16:5
0 | strapi |在异步CORS
(/home/bliss/strapi/node_modules/@koa/cors/index.js:56:32)0 | Strapi |
在异步
/home/bliss/strapi/node_modules/@strapi/strapi/lib/middlewares/errors.js:13:7
0 | strapi |在异步会上
(/home/bliss/strapi/node_modules/koa-session/index.js:41:7)0 | strapi
|在异步
/home/bliss/strapi/node_modules/@strapi/strapi/lib/services/metrics/middleware.js:29:5
0 | strapi | [2022-05-20 17:25:35.517] http:get /favicon.ico(1 ms)
200
I have managed to create a sendgrid account and installed the strapi sendgrid npm package to get Strapi to automatically send a confirmation email with link for confirmation to a new user signing up.
However I noticed that in the email the confirmation link shows:
http://0.0.0.0:1337/api/auth/email-confirmation?confirmation=d48f20893fed7a1b0854b12996d409c31f3c7f9c
The first problem with this is the ip address of 0.0.0.0 which is not the correct ip address of my strapi....let us say my ip address is 1.1.1.1 .....
How do I get the URL to point to the correct IP address when sending the confirmation email? I don't seem to find the field to change in the Stapi backend to make changes to the URL....
Secondly when I change the 0.0.0.0 to my correct IP address and leave the rest the same....the link doesn't seem to work and the email in my User in the strapi back end does not confirm the email itself.
How do I make sure that the confirmation link of Strapi actually works to confirm and authenticate the email of the new user???
=======================================
==========
I have changed my config/server.js file to the following:
module.exports = ({ env }) => ({
host: env('HOST', 'MY_IP_ADDRESS'),
port: env.int('PORT', 1337),
app: {
keys: env.array('APP_KEYS'),
},
});
So the confirmation link I am now receiving shows the following:
MY_IP_ADDRESS:1337/api/auth/email-confirmation?confirmation=395d52db4863d7617427f65ae7010ece32d2b2da
However when I copy and paste the link to a browser (same as clicking it) I get:
{"data":null,"error":{"status":500,"name":"InternalServerError","message":"Internal Server Error"}}
When I do pm2 logs
it shows the following errors:
0|strapi | [2022-05-20 17:25:35.196] error: Undefined attribute level
operator confirmationToken 0|strapi | Error: Undefined attribute
level operator confirmationToken 0|strapi | at
processAttributeWhere
(/home/bliss/strapi/node_modules/@strapi/database/lib/query/helpers/where.js:82:13)
0|strapi | at processWhere
(/home/bliss/strapi/node_modules/@strapi/database/lib/query/helpers/where.js:176:36)
0|strapi | at
/home/bliss/strapi/node_modules/@strapi/database/lib/query/helpers/where.js:104:29
0|strapi | at Array.map () 0|strapi | at
Object.processWhere
(/home/bliss/strapi/node_modules/@strapi/database/lib/query/helpers/where.js:104:18)
0|strapi | at Object.processState
(/home/bliss/strapi/node_modules/@strapi/database/lib/query/query-builder.js:234:29)
0|strapi | at Object.getKnexQuery
(/home/bliss/strapi/node_modules/@strapi/database/lib/query/query-builder.js:271:12)
0|strapi | at Object.execute
(/home/bliss/strapi/node_modules/@strapi/database/lib/query/query-builder.js:352:25)
0|strapi | at Object.findOne
(/home/bliss/strapi/node_modules/@strapi/database/lib/entity-manager.js:121:10)
0|strapi | at processTicksAndRejections
(node:internal/process/task_queues:96:5) 0|strapi | at async
Object.findOne
(/home/bliss/strapi/node_modules/@strapi/strapi/lib/services/entity-service/index.js:67:20)
0|strapi | at async Object.emailConfirmation
(/home/bliss/strapi/node_modules/@strapi/plugin-users-permissions/server/controllers/auth.js:381:18)
0|strapi | at async returnBodyMiddleware
(/home/bliss/strapi/node_modules/@strapi/strapi/lib/services/server/compose-endpoint.js:52:18) 0|strapi | at async policiesMiddleware
(/home/bliss/strapi/node_modules/@strapi/strapi/lib/services/server/policy.js:24:5)
0|strapi | at async serve
(/home/bliss/strapi/node_modules/koa-static/index.js:59:5) 0|strapi |
at async returnBodyMiddleware
(/home/bliss/strapi/node_modules/@strapi/strapi/lib/services/server/compose-endpoint.js:52:18) 0|strapi | at async policiesMiddleware
(/home/bliss/strapi/node_modules/@strapi/strapi/lib/services/server/policy.js:24:5)
0|strapi | at async
/home/bliss/strapi/node_modules/@strapi/strapi/lib/middlewares/body.js:51:9
0|strapi | at async
/home/bliss/strapi/node_modules/@strapi/strapi/lib/middlewares/logger.js:22:5
0|strapi | at async
/home/bliss/strapi/node_modules/@strapi/strapi/lib/middlewares/powered-by.js:16:5
0|strapi | at async cors
(/home/bliss/strapi/node_modules/@koa/cors/index.js:56:32) 0|strapi |
at async
/home/bliss/strapi/node_modules/@strapi/strapi/lib/middlewares/errors.js:13:7
0|strapi | at async session
(/home/bliss/strapi/node_modules/koa-session/index.js:41:7) 0|strapi
| at async
/home/bliss/strapi/node_modules/@strapi/strapi/lib/services/metrics/middleware.js:29:5
0|strapi | [2022-05-20 17:25:35.517] http: GET /favicon.ico (1 ms)
200
发布评论
评论(1)
更新:根据您共享的日志,我能够跟踪 on Strapi github问题上的错误报告。该错误已修复了一周前,并作为4.1.11版的一部分发布。尝试将Strapi更新到此版本,看看是否仍会发生错误。
感谢您使用SendGrid!不幸的是,您的问题是由Strapi引起的,无论您使用的电子邮件提供商如何,您都会遇到此问题。
如果您使用默认配置在本地运行Strapi,则 应该解决您的Strapi应用程序,因此确认电子邮件中的URL也应起作用。
用于此URL的主机和端口是从 .env 文件中获取的,默认情况下看起来像这样:
您可以根据需要更改主机和端口。如果出于某种原因,0.0.0.0不起作用(在我的机器上起作用),请尝试将主机更改为IP,将主机更改为Localhost或127.0.0.1。
如果您将确认电子邮件发送给另一台计算机上的用户,则他们将无法访问您本地运行的Strapi实例。
当您将Strapi应用程序部署到生产中时,您需要更新 .env 文件,或覆盖环境变量以其他方式匹配生产计算机的配置。
Update: Based on the logs you shared, I was able to track down a bug report on strapi's GitHub issues. The bug has been fixed a week ago and is released as part of version 4.1.11. Try updating strapi to at least this version and see if the error still occurs.
Thank you for using SendGrid! Unfortunately, your issue is caused by strapi and you'll run into this issue regardless of the email provider you're using.
If you're running strapi locally using the default configuration, http://0.0.0.0:1337 should resolve to your strapi application, and thus the URL in the confirmation email should also work.
The host and port used for this URL is grabbed from the .env file which by default looks like this:
You could change your host and port as you like. If for some reason 0.0.0.0 doesn't work (it works on my machine), try changing the host to your IP, to localhost, or to 127.0.0.1.
If you're sending a confirmation email to a user that is on another machine, they won't be able to access your locally running strapi instance.
When you deploy your strapi application to production, you'll need to update the .env file or override the environment variables some other way to match the configuration of your production machine.