0

I am making an app where i can create devices and list them, before i can create devices i need to login with /login this works just fine. But when i try to /logout or get /secure info it doesnt work anymore. Any help would be nice!

So in my backend server.js file i do a login this works fine

app.post('/login', (req, res) => {
  console.log("Trying to authenticate user");

  // Never, ever thrust client side data !
  const validation = validate(req.body, AuthenticationSchema.login.body);
  if (!validation.valid) {
    return res.status(400).send({
      message: 'Invalid user information',
      errors: validation.errors.map(e => e.stack)
    });
  }

  passport.authenticate('local', (err, user, info) => {
    if (err) return res.status(500).send({ message: 'User authentication failed drastically'}); 
    if (!user) return res.status(400).send({message: 'Credentials invalid'})
    console.log("User found and logging in");
    req.login(user, (err) => {
      if (err) return res.status(500).send({message: 'Login action failed'})

      res.send(user);
    })
  }) (req, res) //middleware
})

/login works

But when i tried to get the secure info for my profile or logout it doesnt work.

app.get('/secure', is_authenticated, (req, res) => {
  res.send({
    message: "this is secured information",
    user: req.user
  })
})

app.delete('/logout', is_authenticated, (req, res) => {
  req.logout();
  res.send({
    message: 'Succesfully logged out'
  })
})

logout and secure

Note: i think it has something to do with isAuthenticated() that comes automatically false in netlify, in postman it just works fine, and when i try it locally it also just works fine.

postman

arthur
  • 1
  • Does this answer your question? [How to send authorization header with axios](https://stackoverflow.com/questions/44245588/how-to-send-authorization-header-with-axios) – Mat J Dec 09 '21 at 07:44

0 Answers0