Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strapi return error code 400 on user registeration, when email verification is on

  • I have installed the send grid module for strapi.

    npm i strapi-provider-email-sendgrid

  • configured the email plugin ![enter image description here
  • Role and permissions setting enter image description here

  • But still whenever I register a user Error code 400 is return, also No mail is being sent.

    POST /auth/local/register

enter image description here

  • However the user is created in strapi's Users content type enter image description here

  • Console screenshot.

    List item

Help me in dealing with it!!

like image 590
Ayush Rajniwal Avatar asked Dec 25 '19 17:12

Ayush Rajniwal


3 Answers

The error management of the email plugin is not good, we have to change it!

This error is probably provided by this code line

To got the correct error, I suggest you to add a console.log of the err in your strapi-provider-email-sendgrid node_module directly.

I know it's not good to do that but it will be the only way to know the error that you have.

like image 188
Jim LAURIE Avatar answered Sep 21 '22 06:09

Jim LAURIE


I faced similar issues with the AWS SES email provider from Strapi, so I'll leave my resolution here in case someone googles their way into this question in the future.

That error message is actually thrown by the Sendgrid Strapi email provider in line 58 (https://github.com/strapi/strapi/blob/dae9cfa415881f17ebb95d9ea3887c6a0ae0dca6/packages/strapi-provider-email-sendgrid/lib/index.js#L58).

There's a catch that will swallow exceptions thrown by the Sendgrid library and throw instead this generic message. Here are your options to figure out what the actual error is:

  1. Debug the provider by attaching to the running NodeJS process
  2. Add some console.log statements to the node_modules/strapi-provider-email-sendgrid/lib/index.js file inside the catch and inspect your standard output
  3. Modify the call to reject inside the catch to return the actual error.message string. This might require looking into how Strapi will handle errors thrown inside controllers to make sure it doesn't end up getting lost in the I18N midlleware or other extension points.
like image 45
Sergio Leon Avatar answered Sep 18 '22 06:09

Sergio Leon


I had the same problem with strapi/sendgrid. The problem was the fact that the sender was not a verified email in sendgrid.

Step to fix:

  • I looked for : id: 'Auth.form.error.email.invalid' in my node_modules.

  • Then, I logged the error

   sendgrid.send(msg, function(err) {
     if (err) {
      console.log(err.response.body.errors)     
      reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]);
     } else {
       resolve();
   } 
  • I had the following message inside the error : "The from address does not match a verified Sender Identity. Mail cannot be sent until this error is resolved. Visit https://sendgrid.com/docs/for-developers/sending-email/sender-identity/ to see the Sender Identity requirements"

  • So, i went to sendgrid and verified my sender's emails. And it worked :)

like image 43
Marie Q Avatar answered Sep 20 '22 06:09

Marie Q