idpokute
idpokute

Reputation: 608

How to restrict page from logged-in user

I'm using Passport-jwt with Express. I'd liket to restrict pages from logged-in user by middle-ware.

For example, I have a page, /dear-not-sign-in-user After a user logged-in, the user can't access the page. So basically I'd like to implement the opposite of passport.authenticate method. How can I detect the user's token is not valid?

router.get(
  "/dear-not-sign-in-user",
  !passport.authenticate("jwt", { session: false }),
  (req, res) => {
    console.log('this user is not logged-in yet');
  }
);

Above code doesn't work, but you get the idea what I want to do.

Upvotes: 1

Views: 93

Answers (0)

Related Questions