0

Is this possible to send session ID in header via post request

Here is my code in express JS :

app.use(session({

secret: 'newsession',

saveUninitialized:false,

resave:false,

cookie: {

    secure: false,

    httpOnly:false,


}}));


app.post ('/login', function (request, response, next) {

const { username  , password } = request.body

db.find(db.COLLECTIONS.USERS,{username: username, password: password}).then((users) => {

    if (users.length !== 0) {
        request.session.isAuth=true;
        response.status(200).json(users[0]);
    } else {

        response.status(409).send("Username not found");
    }
}).catch(() => {
    response.status(409).send();
});

});

now when I am going send post request in postman using JSON type for example:

  {

 "username":"user",
 "password":"user"

  }

I want to know is it possible to send session id in header to client from server ?

Mohammad FA
  • 41
  • 1
  • 5

1 Answers1

2

Not sure what exactly you want to perform. Anything you can send in headers via below syntax

res.set(field, [value])

or

res.header(field, [value])

Ex:

res.set('Content-Type', 'application/json');

or

res.header('sessionId', 'yourId');
Meet Patel
  • 73
  • 1
  • 9