how to fetch reset password api in front-end Node js

I’m student in web development. Currently, I’m trying to build a basic project, where I’m stack in implementing reset password feature, I really need help in how fetching reset password API in front-end using Axios. In short, the reset password API that I implemented works fine on Postman, but whenever I tried to pass in front-end and fetch the API in order to enable users to enter their new password and passwordValidation I kinda lost, below I share my code snippets:

backend code reset password:

resetPassword = async(req, res) => {
  try {
    // Step 1: Get user based on the token
    const validateHashedToken = crypto

    const user = await User.findOne(
                  passwordResetToken: validateHashedToken,
                  passwordResetExpires: { $gt: }
    user.password = req.body.password;
    user.passwordValidation = req.body.passwordValidation;
    user.passwordResetToken = undefined;
    user.passwordResetExpires = undefined;

    // Step 3: Update the "passwordChangedAt" date
    // Step 4: Log the user in and send a JWT
    genResJWT(user, 200, res);

  } catch (error) {
    console.log('error', error)




exports.getResetPasswordUrl = async(req, res) => {
  try {
    const { token } = req.params.token;
    const validToken = await User.findOne(
        passwordResetToken: token

    title: 'resetpassword',
    token: validToken
  } catch (error) {

exports.resetpassword = (req, res) => {
  // I'm stack here and I really need help
  res.status(200).render('profile', {
    title: 'reset password successfuly'

front-end fetching api code:

import axios from 'axios';

export const resetPassword = async (password, passwordValidation) => {
  try {
    const res = await axios({
      method: 'PATCH',
      data: {

    if ( === 'success') {
      window.setTimeout(() => {
      }, 500);
  } catch (error) {

I added to my index.js the submit handler:

if (resetPasswordForm) {
  resetPasswordForm.addEventListener('submit', e => {

    const password = document.getElementById('password').value;
    const passwordValidation = document.getElementById('passwordValidation').value;
    resetPassword(password, passwordValidation);

I have the same error that persisted, even I tried to walk through some tutorials and a bunch of youtube videos, I end up with the same behavior, to focus more on the error I added a screenshot of my console whenever I hit the ‘reset password’ button “”, seems to be TypeError: “x” is (not) “y” error.

please help me!

Submit an answer
Answer a question...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer