The request to send an OTP using the endpoint "http://localhost:4000/api/v1/auth/sendotp" returned a

While working on a project, I encountered an issue with sending an OTP to the provided email upon sign up. Initially, everything was functioning correctly when tested using Postman; however, after connecting the backend and frontend and attempting to send the OTP, an error is being thrown in the console.

The error message states "SENDOTP API ERROR............"

  1. AxiosError {message: 'Request failed with status code 401', name: 'AxiosError', code: 'ERR_BAD_REQUEST', config: {...}, request: XMLHttpRequest, ...}

    1. code: "ERR_BAD_REQUEST"

    2. config: {transitional: {...}, adapter: Array(2), transformRequest: Array(1), transformResponse: Array(1), timeout: 0, ...}

    3. message: "Request failed with status code 401"

    4. name: "AxiosError"

    5. request: XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, ...}

    6. response: {data: {...}, status: 401, statusText: 'Unauthorized', headers: AxiosHeaders, config: {...}, ...}

    7. stack: "AxiosError: Request failed with status code 401\\n at settle (http://localhost:3000/static/js/bundle.js:144559:12)\\n at XMLHttpRequest.onloadend (http://localhost:3000/static/js/bundle.js:143244:66)"

    8. [[Prototype]]: Error

Currently, signing up triggers an error instead of sending the expected OTP to my email address.

Below is the snippet from my API connector file:

import axios from "axios"

export const axiosInstance = axios.create({});

export const apiConnector = (method, url, bodyData, headers, params) => {
    return axiosInstance({
        method:`${method}`,
        url:`${url}`,
        data: bodyData ? bodyData : null,
        headers: headers ? headers: null,
        params: params ? params : null,
    });
}

// Additional APIs can be found in my apis file

For more detailed information on specific API functions, please refer to my authAPI file which includes methods for sending OTP, signing up, logging in, resetting passwords, and more.

If you need further details or assistance, feel free to explore the functionalities mentioned above for a better understanding of the process.

Answer №1

If you're getting the error, your environment file might be missing important information like the Base URL. Be sure to create a .env file and save the necessary Backend URL in it.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Uh-oh, looks like we've hit a snag: the module '../time/convert' is nowhere to be found. This issue seems to be

I recently set up a new Angular project on Linux, committed it to Git, and then cloned it onto Windows. Using Bower and NPM, I successfully loaded everything except for one error that only occurs on Windows. Upon performing a recursive grep search for ../ ...

Setting the default views directory in express - A guide

I am currently struggling with setting up my routes in express.js properly. Below is a snippet of my code: express.js configuration app.set('views', config.root + '/app/views') app.set('view engine', 'jade') rout ...

npm local installation encounters initial failure

Context In my project, I have a package.json file containing multiple development dependencies. I prefer to use local installation by running npm install with the specified package.json node -v v0.10.26 npm -v 1.4.4 Windows 7 x32bit Issue Upon the i ...

NodeJs ERROR: Module not found

When trying to launch an instance running ubuntu with express, I encountered a module not found error that does not occur on my Windows machine. Error Message: node:internal/modules/cjs/loader:1085 throw err; ^ Error: Cannot find module './src/c ...

Creating a custom color palette with Material UI using ThemeProvider

Attempting to set a custom color for a Button using createMuiTheme and ThemeProvider has been successful with the primary and secondary palettes. However, when trying to utilize an alternate color such as "info", it does not seem to work as expected: http ...

Adding an authentication header in redux-api-middleware: steps and best practices

Procedure import { CALL_API } from 'redux-api-middleware'; export const MOVIES_GET_SUCCESS = 'MOVIES_GET_SUCCESS'; export const fetchMovies = () => { return { [CALL_API]: { endpoint: 'http://localhost:3005/api/mov ...

keen-slider may encounter compatibility issues with next.js

I have been attempting to transform the code shown in the screenshot below into a slider format using keen-slider. https://i.stack.imgur.com/M62iz.png <div className="card-con mt-6"> {!loadingImages && ...

Experiencing unfamiliar typescript glitches while attempting to compile a turborepo initiative

I have been utilizing the turborepo-template for my project. Initially, everything was running smoothly until TypeScript suddenly started displaying peculiar errors. ../../packages/fork-me/src/client/star-me/star-me.tsx:19:4 nextjs-example:build: Type erro ...

What is the best way to set a javascript variable as the props value for a component in React?

I decided to create a new component called CheckboxFilter. In order to utilize it and assign properties to it, I need to pass props with the value of a JavaScript variable : const FilterWrapper = ({ component, filterLabel, requiredField, ...others }) => ...

issue with logging in, token verification failed

My current project involves creating a login system with authorization, but for some reason the token is not being transferred properly. const path = require('path'); const express = require('express'); const bodyParser = require(' ...

Deployment of the website resulted in a NextJS 500 internal server error, yet the build functions flawlessly when tested locally

Everything runs flawlessly on my personal computer using pm2. There are no errors, every page loads perfectly, and fetching files does not result in any 404 or 500 errors. It's absolutely fantastic! This is exactly how I envision it working. However, ...

Tips for launching a React Native application with a Node.js backend on an Android device?

Currently, I'm facing an issue while trying to run my React Native app on my local Android Device. The app utilizes Node.js APIs to retrieve data from a MySQL database. However, the problem arises when my Android device is unable to access the Node.js ...

Tips for Synchronizing package.json and package-lock.json When Dependency Versions Do Not Match

What's Going On In my Package.json file: "dependencies": { ... "node-sass": "^4.13.0" ... } Executing npm install In package-lock.json: "node-sass": { "version": "4.13.1", ... } Actions Taken So Far 1. I tried deleting: pack ...

When utilizing the `express.static(__dirname)` function in Node.js with Express, the visitor may be directed to an incorrect HTML page

My website consists of a login page named login.html and an index page named index.html. I want to implement authentication so that only logged in users can access the index page. I have not set up the post method on the login HTML page. Therefore, I have ...

Struggle with typescript integration with emotion and styled components

Issue Description: I encountered an issue while working with typescript and emotion/styled libraries. When attempting to specify the type of the parent component that wraps a styled component, I faced difficulties. The scenario involves a parent componen ...

The reference to React in useContext is currently undefined

I am currently working on a React App that involves CRUD operations connected to a Rails API. The project structure is as follows: App.js -> UserIndex --> Form --> User -> User My goal is to pass a function from <App /> to its gr ...

Discover multiple keys within a new Map object

Our usual approach involves creating a new Map like this: const hash = new Map() hash.set(key,value) To retrieve the information, we simply use: hash.get(specificKey) An advantage of using Map is that we have flexibility in choosing keys and values. Cur ...

What is the destination for next() in Express js?

I'm new to javascript, nodejs, and express, and facing confusion with the usage of next(). I am trying to make my code progress to the next router using next(), but it seems to be moving to the next then instead. This is what my code looks like: // ...

Creating a Material UI Dialog with a see-through background color: a step-by-step guide

I'm struggling to create a loading status indicator using Material UI. I want the background color of the dialog box to be transparent and I also need to adjust the height, but I can't seem to achieve this with the provided style options. Any sug ...

Enhance the source code by integrating navigation features into a React Native application

I would like to modify the calendar code so that clicking on any day of the week will open the ScanPhoto page. However, I am unsure of how to accomplish this task. My current code seems correct but there appears to be a syntax error when trying to naviga ...