Next js Strapi forgot password email

936 Views Asked by At

I'm trying to send reset password email to the email provided by user in the forgot password form but get an error "Internal Server Error" ..

this is the function called when submit the form:

`

const onFinish = async (values) => {
  
      setIsLoading(true);
      axios
  .post(getStrapiURL('/api/auth/forgot-password'), {
    email:values.email,
  })
  .then(response => {
    message.success('Reset password email was sent successfully !',4);
  })
  .catch(error => {
    console.log('An error occurred:', error);
    message.error(error.response.data.error.message,3);
  });
    };

`

Next , based on strapi docs , I have installed sendgrid provider package and add its config in /config/plugins.js

`

module.exports = ({ env }) => ({
    // ...
    email: {
      config: {
        provider: 'sendgrid', // For community providers pass the full package name (e.g. provider: 'strapi-provider-email-mandrill')
        providerOptions: {
          apiKey: process.env.SENDGRID_API_KEY,
        },
        settings: {
          defaultFrom: '[email protected]',
          defaultReplyTo: '[email protected]',
         
        },
      },
    },
    
    'users-permissions': {
      config: {
        jwt: {
          expiresIn: '7d',
        },
      },
    },
  });

` Now when i submit the forgot password form with Recipient email ,the error says "Internal Server error" also its failed when i test it from strapi dashboard .. any help please! (Next js with Strapi project)

1

There are 1 best solutions below

0
Nadir Hussain On

In Addition to those configurations, please make sure to define template for

  1. Reset Password
  2. Email address confirmation (if needed).

enter image description here

Provide same email with which you have registered to sandgrid.

  • Make sure sandgrid is installed in your app.

  • Use original email to send and receive emails. Google may not allow to send SMTP emails

  • from your account, which you may have to look for.

Thanks