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
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:
HOST=0.0.0.0
PORT=1337
...
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.