Put the code in the reset password url into my request

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 :


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)) :

.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:

.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


okok, sorry if don’t understand everything :sweat:, 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 :frowning: I believe our documentation examples are based around react.

Gatsby is the same as react :wink:

is just that I don’t know how to access to this code into the url :sweat_smile:

Maybe something like this can help?


Yes it helped !!, I finally have my urlCode


can you please hide my back url :sweat_smile:

Sure, Edited :wink:

1 Like