how to set session in front(nuxtjs)?

0

Issue

I have code to set the session that works in postman

First: set my session and it work

const user = {
  name: 'afshin',
};
req.session.user = user
res.status(200).send({data:req.session.user,status:200});

Second: retrieve session

console.log(req.session.user)

This works when I make a request with postman. But when I use on client (nuxt + axios) it isn’t working

Third: on the front-end

this.$axios
  .post(
    'http://localhost:7000/auth/session-result',
    { data: 'salam' },
    {
      headers: { 'Content-Type': 'application/json' },
    },
    { withCredentials: true },
  )
  .then((res) => {
    console.log(res)
  })
  .catch((error) => {
    console.log(error)
    this.setState({
      errorMessage: `Server Error`,
      loading: false,
    })
  })

What am I doing wrong the front-end?

Solution

req is for server side, so you will not get it on the client side, as shown on this page, this is only for server side.

Answered By – kissu

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More