Strapi email confirmation is not working properly. I click the link and nothing happens
Asked Answered
C

1

2

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

Coster answered 20/1, 2022 at 15:30 Comment(0)
R
10

eStrapi 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. Create this folder structure under config --> env --> production -> server.js and paste this in the file:

  module.exports = ({ env }) => ({
    host: env('HOST'),
    port: env.int('PORT'),
    url: env('BACKEND_URL'),
});
  1. 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('BACKEND_URL_LOCAL'),
        });

inside your .env variables add your server url's for hosted and local, Make sure you set your NODE_ENV for the proper environments:

    BACKEND_URL=https://my-app.herokuapp.com
    BACKEND_URL_LOCAL=http://localhost:1337
    # 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.

Rose answered 20/1, 2022 at 16:39 Comment(5)
Hi does the link to confirm email suppose to work out of the box without anymore extra programming? I got my link MY_IP_ADDRESS:1337/api/auth/email-confirmation?confirmation=33c73ae3d609a7d23e32180aea643b03ce78f273 to be sent to the email but when I go to the link by pasting it to the browser I get nothing and the email does not get confirmed....Mozell
so it seems like MY_IP_ADDRESS:1337/api/auth/email-confirmation endpoint is not setup properly.....Mozell
thankyou for the explanation! you beat the docs hands down ha ha. The part thats confusing is that the email link hits a backend endpoint, then redirects the confirmed user to the frontGalenism
Ummm ... question, how does the frontend page then access the user's id so they can be logged in and their details pulled?Galenism
Hi @Mozell what was the fix for the endpoint? I also have the same issue. address:1337/api/auth/email-confirmation?confirmation=33c73ae3d609a7d23e32180aea643b03ce78f273Kulsrud

© 2022 - 2024 — McMap. All rights reserved.