- in this project i am testing each route after coding it.when i was testing my authantication ,i got my jsonwebtoken(from postman after applying post request).Now when i set my header key as:x-auth-token and its value as jwtwebtoken(that i got from postman),instead of getting same data stored in mongodb data base with an id,it shows me just a boolean value "false".no error showing in console.i am not surewhere i am going wrong.please help*
middleware auth.js file
const jwt=require("jsonwebtoken");
const config=require("config");
module.exports=function(req,res,next){
//get token from header
const token=req.header("x-auth-token");
//check if not token
if(!token){
return res.status(401).json({msg:"No token authorization"});
}
//verify token
try{
const decoded=jwt.verify(token,config.get("jwtSecret"));
req.user=decoded.user;
next();
}catch(err){
res.status(401).json({msg:"Token is not valid"});
}
} ;
route api auth.js file
const express=require("express");
const router=express.Router();
const auth =require('../../middleware/auth');
const User = require('../../models/User');
//@route Get api/auth
//does test route
//@acess Public
router.get("/",auth,async (req,res) =>{
try{
const user=await User.findById(req.user.id).selected("-password");
res.json(user);
}catch(err){
console.error(err.message);
res.status(500).send("server error");
}
});
module.exports=router;
this is the url on which i am getting "false" on sending get request from postman