I am trying to read a cookie(which i have set in the backend) in the frontend but getting undefined
Here is the backend code
async createUser (req, res){
const newUser = new userModel(req.body)
try {
await newUser.save()
const token = jwt.sign({ _id: newUser._id }, process.env.SECRET_KEY, { expiresIn: '60 days' });
// setting cookie
res.cookie('socialAuthToken', token, { maxAge: 900000, httpOnly: true });
console.log(res.cookie)
return res.status(200).json({
user: newUser,
message: "Successfully signed up!"
})
} catch(e){
console.log(e)
return res.status(400)
}
res.end()
}
I have tested the backend using postman and it is storing the socialAuthToken in the cookies but when I am using the react frontend to get the cookie it showing undefined
Frontend code:
import React, { useState, useEffect } from 'react';
import axios from 'axios'
import Cookies from 'js-cookie'
function ShowUser(){
var value = Cookies.get('socialAuthToken')
console.log(value)
}