I am new to node js and am developing a simple website. when sending an unregistered username to the server, instead of getting the "username/password does not exist", I am getting "POST http://localhost:3001/auth/login 400 (Bad Request)". can someone plz help me figure out this problem? thank you.
my middleware
my Post request
my route
const router = require("express").Router(); const {loginUser, registerUser} = require("../controllers/authController.js");
router.post('/register', registerUser); router.post('/login', loginUser);
module.exports = router;
CodePudding user response:
I think you are getting this error because you are not passing the userdata
to the login
function. I'm not sure but try using below code:
const login = (loginUser, loginPassword) => {
axios.post('http://localhost:3001/auth/login', {
username: loginUser,
password: loginPassword
}).then(...)
}
CodePudding user response:
You have a route issue! in you route you have:
router.post('/login', loginUser);
And in you test you have:
http://localhost:3000/auth/login
So you need to either add auth
in your route definition or remove auth
in your axios post
CodePudding user response:
Many things can go wrong. I recommend you to just run the app with a debugger and just check line by line where something is wrong. I see you are using Visual Studio Code. There are many Youtube videos on how to run the app with the debugger.