I want to set up a reset password feature. I send an email containing a link with a code in the url. Something like this :
http://localhost:8000/resetpassword/?code=8d8291822810f46ad2a54a8b7fbc06b586ddf2d5acc1ad65ed8c5875f730d3e4afbcc98816de64cf307004c261a2ab9eb8b8a3354ed448f08a6a8ac712f472cf
But now, according to the documentation, I have to paste the url code into my back request, but I don’t know how to add dynamically this url code into the request (maybe is something like this : $(urlCode)) :
axios
.post('https://localhost:1337/auth/reset-password', {
code: 'UrlCode', ***<= I need the url code here***
password: 'userNewPassword32',
passwordConfirmation: 'userNewPassword32',
})
.then(response => {
console.log("Your user's password has been reset.");
})
.catch(error => {
console.log('An error occurred:', error.response);
});
}
the code needs to be part of the query parameters and not part of the body so something like:
axios
.post('https://blah.herokuapp.com/auth/reset-password' + '?code=' + UrlCode, {
password: 'userNewPassword32',
passwordConfirmation: 'userNewPassword32',
})
hey, thank you for your answer, but I don’t know how to have the urlCode into a variable
It should be passed to your frontend via a Query variable (assuming you have modified the password reset URL in the Users & Permissions plugin), your frontend would read that and inject it into the POST request back to Strapi to update the user.
this is process flow:
- User requests a password reset
- Email is sent to the user with the URL => Point of Sales
- User clicks link and is taken to your frontend
- Frontend captures the code from the query parameters, waits for user to enter their new password
- User hits “submit” or whatever on your frontend
- Frontend injects the previous code into the query parameters + the new password information in the body and fires a POST request to Strapi
- Strapi replies if success or failure
Here is the relevant docs: https://strapi.io/documentation/v3.x/plugins/users-permissions.html#forgotten-reset-password
2 Likes
okok, sorry if don’t understand everything
, in my frontend page, urlCode is undefined, but you tell me that I can access to this urlCode from the query parameters, how can I access to this query (knowing I’m using Gatsby )
something like this ?
import { useStaticQuery, graphql } from “gatsby”
const { site } = useStaticQuery(
graphql query { site { siteMetadata { title description author image siteUrl } } }
)
On a side note, it does appear the code should be in the body not the query parameters on the call to Strapi, my bad there.
I’m not familiar with Gatsby sorry
I believe our documentation examples are based around react.
Gatsby is the same as react 
is just that I don’t know how to access to this code into the url 
Maybe something like this can help?
2 Likes
Yes it helped !!, I finally have my urlCode
2 Likes
can you please hide my back url 