Passport: No Mention of isAuthenticated() in docs

Created on 12 Jun 2018  路  6Comments  路  Source: jaredhanson/passport

Hi,
The method isAuthenticated() is not mentioned anywhere in the docs.Also is there any method named isUnauthenticated() too?

Most helpful comment

There is no bug... The thing is that the isAuthenticated() and isUnauthenticated() functions are not mentioned anywhere in the docs. A lot of people keep requesting that this should be in the documentation since the whole point of using passport is for authenticating the user... I really don't know why this was not added yet, I could find an issue in GitHub from 2016 asking for this...

All 6 comments

Yes this is a big omission since it's kind of the point of the library :) Here's a page documenting it: https://stackoverflow.com/questions/17756848/only-allow-passportjs-authenticated-users-to-visit-protected-page

Here's example code. Feedback on better approaches would be appreciated:

const express = require('express');
const app = express();

// must be the first defined route
app.all('*', (request, response, next) => {
  let publicRoutes = ['/register', '/login', '/logout'];
  (publicRoutes.includes(request.path) || request.isAuthenticated()) ? next() : response.sendStatus(401);
});

app.get('/myprotectedroute', (request, response) => response.send('Hello!'));
app.listen(3000);

So what's the bug here?

There is no bug... The thing is that the isAuthenticated() and isUnauthenticated() functions are not mentioned anywhere in the docs. A lot of people keep requesting that this should be in the documentation since the whole point of using passport is for authenticating the user... I really don't know why this was not added yet, I could find an issue in GitHub from 2016 asking for this...

Just started using Passport and really struggled with this. Some mention in the docs would be good!

Can't believe this issue is not fixed yet, it's been 2.5 years but they haven't updated the docs to solve the problem.

also the examples page for passport-local doesn't exist anymore.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JSteunou picture JSteunou  路  7Comments

angel1st picture angel1st  路  5Comments

Manubi picture Manubi  路  6Comments

PymZoR picture PymZoR  路  3Comments

ksmithut picture ksmithut  路  6Comments