Search code examples
expressauthenticationloopbackjsloopback

401 Unauthorized when trying to logout from Loopback's built in user management


I followed the steps found at the https://loopback.io/doc/en/lb2/Logging-in-users.html tutorial.

I am able to log-in correctly and I am given a unique Access Token, however logout throws a "401 Unauthorized". The headers contain the access token that I was given.

How can I logout?


Solution

  • Thanks everyone. The issue was 'body-parser' configuration issue. The server.js should look like:

    var bodyParser = require('body-parser');
    var app = module.exports = loopback();
    
    app.use(bodyParser.urlencoded({extended: true})); //Configure body parser
    app.use(loopback.token()); //Use access tokens
    

    If you extend from the user-management example it will be already configured. Blank applications do not include this configuration.