in

Cannot read property ‘jwtoken’ of undefined


DEV Community


DEV Community is a community of 712,122 amazing developers

We’re a place where coders share, stay up-to-date and grow their careers.

Oct 14 ’21
Comments: 1
Answers: 0


0



here I generate the token at backend in express
…………..

router.post("/login",async(req,res)=>{
    const {email,password}=req.body;
    if(!email || !password){
        return res.status(401).send({error:"please filled the data properly"});
    }
    try {
        const loginUser=await User.findOne({email:email});
        if(!loginUser){
            return res.status(400).send({error:"not found"});
        }
        const isMatch = await bcrypt.compare(password,loginUser.password);    
        if(isMatch){
            const token=await loginUser.generateToken();
            res.cookie("jwtoken",token,{
                expires:new Date(Date.now()+15000000),
                httpOnly:true,
                //secure:true  //it

Discussion (0)



Source: https://dev.to/suvamray/cannot-read-property-jwtoken-of-undefined-jik

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

GIPHY App Key not set. Please check settings

Vodafone Idea Rs 249 Plan a Better Option than Jio’s Offering

Palm is making a pair of earbuds for that tiny Android phone you forgot about thumbnail

Palm is making a pair of earbuds for that tiny Android phone you forgot about