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

Redirects #8

Open
mylastore opened this issue Oct 10, 2017 · 4 comments
Open

Redirects #8

mylastore opened this issue Oct 10, 2017 · 4 comments

Comments

@mylastore
Copy link

mylastore commented Oct 10, 2017

how can I handle redirect at the control level? example if you go to url/admin take them back to sign in page if not an admin.

@JREastonMarks
Copy link

Are you asking if the user is not authenticated (Not Logged In), not authorized (Does not have role), or is not that user(Logged in as a different user)?

@mylastore
Copy link
Author

@JREastonMarks actually both

@JREastonMarks
Copy link

Sorry about the extreme delay in getting back to you.

Here is a copy of the code that I use. If a users authorizedStatus is not authorized then I render a login page otherwise I just allow the req to happen as usual.

I use express and I typically have two different pages. One for a user that is logged in, and one that requires them to log in.

app.set('permission', {
  after: function(req, res, next, authorizedStatus) {
    if (authorizedStatus !== 'authorized') {
      res.render('pages/login', {});
    } else {
      next();
    }
  }
});

FULL DISCLOSURE: This may not be best practice and I welcome any response that has a better way of solving this.

@mylastore
Copy link
Author

That worked but I use redirect instead of render res.redirect('/login' || {});

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

No branches or pull requests

2 participants