Home > front end >  Strapi email confirmation is not working properly. I click the link and nothing happens
Strapi email confirmation is not working properly. I click the link and nothing happens

Time:01-21

I'm having issues understanding how the Strapi email confirmation is supposed to work. I get this: http://0.0.0.0/auth/emailconfirmation?confirmation=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9

CodePudding user response:

Strapi has a built in email plugin that handles that, you can also add third party email providers.
The way it works is that Strapi sends a email with a link that has a hash attached to it. When you click it, it will go to SERVER host with a specific endpoint in the URL and the server will automatically validate your email. There are some steps to have to follow:

  1. under your Admin panel go to: settings -> User Permissions Plugin -> email templates enter a VALID shipper and response email for all templates.
  2. Under User Permissions Plugin -> Advanced Settings -> Enable Email Confirmation and add a redirect URL for after it is confirmed. ex. https://your-site.com/login
  3. Under User Permissions Plugin -> Roles -> -> Public -> User Permissions -> Auth -> sendEmailConfirmation checked.
  4. Then inside your code under config -> server.js insure that you add a url key.

    module.exports = ({ env }) => ({
      host: env('HOST'),
      port: env.int('PORT'),
      url: env((process.env.NODE_ENV === 'development') ? 'BACKEND_URL_LOCAL' : 'BACKEND_URL'),
    });

inside your .env variables add your server url's for hosted and local, insure that it has the "/api" or it will not work!!! Make sure you set your NODE_ENV for the proper environments:

    BACKEND_URL=https://my-app.herokuapp.com/api
    BACKEND_URL_LOCAL=http://localhost:1337/api
    # NODE_ENV=production
    NODE_ENV=development

test both your served backend as well as the local. Your full url string should look something like this:

local -> http://localhost:1337/api/auth/email-confirmation?confirmation=6d3a77679db63a94c16307ae133d9373b23c3986

hosted -> https://my-app.herokuapp.com/api/auth/email-confirmation?confirmation=738a515de684eb58dfb5e4aaa7fe7a9f35aa32454

insure that the /api is in both links.

  •  Tags:  
  • Related