Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

access_token null on custom middleware #3416

Closed
mahdinai opened this issue May 21, 2017 · 8 comments
Closed

access_token null on custom middleware #3416

mahdinai opened this issue May 21, 2017 · 8 comments
Labels

Comments

@mahdinai
Copy link

hi

server.js file:

app.use(cookieParser('secret'));
app.use(loopback.token({
  model: app.models.accessToken,
  cookies: ['access_token']
}));

custom middleware:

'use strict';
var user = require('../../common/proxies/UserProxy');

module.exports = status;
function status() {
  return function(req, res,next) {
    

    if (req.accessToken) { // access token is null 
      
      user.getProfile(req.accessToken.userId, function (user_res) {
        if (user_res.result) {
          next();

        }else{

          req.app.locals.msg = {
            hasMessage: true,
            Message: "",
            messageTitle: "",
            alertClassName: "alert-danger",
            app: req.app
          };

          res.redirect('/user/login');
        }
      });
  }else {

      req.app.locals.msg = {
        hasMessage: true,
        Message: "",
        messageTitle: "",
        alertClassName: "alert-danger",
        app: req.app
      };

      res.redirect('/user/login');

    }
  }


}

accesstoken is null in middleware , but work on route :(((

@yshing
Copy link
Member

yshing commented May 23, 2017

Please Check the doc here ..
https://docs.strongloop.com/display/public/LB/Defining+middleware

@ydomenjoud
Copy link

actually this is an excellent question : how to get current user in custom middleware ?

req.accessToken is always undefined

@bitmage
Copy link
Contributor

bitmage commented Aug 8, 2017

In Loopback, there's not 1 kind of middleware, there's about 5. So you have to sort out what order they all run in and how they interact. Personally I dodged this complexity by wedging my own strategy in. Not ideal, but at least I can reason about the order things run in.

@stale
Copy link

stale bot commented Oct 7, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 7, 2017
@stale
Copy link

stale bot commented Oct 21, 2017

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

@stale stale bot closed this as completed Oct 21, 2017
@stale
Copy link

stale bot commented Oct 21, 2017

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

2 similar comments
@stale
Copy link

stale bot commented Oct 21, 2017

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

@stale
Copy link

stale bot commented Oct 21, 2017

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants