Email validation account link wrong base url

Hi i’m using the strapi provider sendgrid for the email. But when an email with a link (to validate an account) was sent, it is a wrong BASE URL : http://localhost:28687/auth/email-confirmation?confirmation=myCode. I set the url in the strapi BO but it doesn’t works in production, i don’t understand what is this : “http://localhost:28687/


Thanks in advance

One of the following (depending if you are using NODE_ENV)

  • ./config/server.js
  • ./config/env/yourNodeEnv/server.js

You need to set the url key to the public domain including the http/https and rebuild your admin panel. https://strapi.io/documentation/v3.x/concepts/configurations.html#server

Hi @DMehaffy your are talking about the url property and i see in the description :
Public url of the server. Required for many different features (ex: reset password, third login providers etc.). Also enables proxy support such as Apache or Nginx, example: mywebsite.com is available for purchase - Sedo.com . The url can be relative, if so, it is used with http://${host}:${port} as the base url. An absolute url is however recommended .`

The example in the description talking about api url ? example: https://mywebsite.com/api
In my case i’ll have two urls :

  • One for my BO and my api like : https//my-strapi-bo.com && https//my-strapi-bo.com/api

  • One for the public website : https//my-public-website.com

And of course i would like, when a link is send by mail, redirect to an url of my public website when an account is validate for example : https//my-public-website.com/register
Should I set the property url with absolute path of my public website ?
no problem doing that?

Thanks

I tried to do this and i have now a CORS to access to the admin bo strapi policy issue :

Capture d’écran 2020-11-24 à 13.22.48

Remove the trailing slash on the url but yes if you have your api routes and admin split you need to use the https://my-strapi-bo.com/api

You will have an issue in routing through trying to mount the admin panel on the root of your strapi domain. We have an open bug report about that here:

See the following guide for Nginx which does also include the server.js settings: https://strapi.io/documentation/v3.x/deployment/nginx-proxy.html#sub-folder-split and https://strapi.io/documentation/v3.x/deployment/nginx-proxy.html#sub-folder-split-strapi-config

@DMehaffy it is not a split between api routes and admin. Admin BO and api routes are on the same domain. I have another domain for my frontend public application and an user can create an account with this application. I would like the link in the email to have the public site url inside and not localhost or strapi BO url

In that case you will need a custom option on your frontend that can parse that parameter and forward it to your Strapi backend application using the

https://your-strapi.com/api/auth/email-confirmation?confirmation=sometoken

You can customize the email template to provide that frontend url but it will require you to build that page.

Hi @DMehaffy i tried your solution and it works now.
I overridden the sendEmailConfirmation method in plugin/users-permissions/services and i changed sur URL sent with my frontend url application (environnement variable) + the token to update an user.
After i create the specific page where I do the GET request auth/confirmation-email with the token passed in params tu validate the account.
For overridde methods in my backend strapi I had to do another route for the email confirmation and copy past the code of the original in the new method. I can’t directly override the existing route auth/email-confirmation.
I don’t know if it is normal, btw it works.
Thanks for your help

Glad you got it working!

hi @Jean1 how did you manage to modify the template of the reset password email ?
I did it in parametres>email templates but I still receive te default one. Any ideas ?

Thanks in advance for your help
Jérémy

Hi @jeremy did you set the url here ?

Yes i did, I display the good url, but the template in parametres>email templates doesn’t show up in my email from sendgrid or AWS SES @Jean1