passport icon indicating copy to clipboard operation
passport copied to clipboard

No Mention of isAuthenticated() in docs

Open prakhar897 opened this issue 7 years ago • 8 comments

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

prakhar897 avatar Jun 12 '18 07:06 prakhar897

Also is there any method named isUnauthenticated() too?

Yes. https://github.com/jaredhanson/passport/blob/597e289d6fa27a2c35d16dd411de284123e3817e/lib/http/request.js#L92-L100

em92 avatar Jun 13 '18 04:06 em92

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);

bfischer1121 avatar Jul 17 '18 02:07 bfischer1121

So what's the bug here?

erick2014 avatar Oct 02 '18 10:10 erick2014

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...

AlecBp avatar Oct 28 '18 05:10 AlecBp

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

brenc avatar Jun 05 '19 18:06 brenc

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.

uzair004 avatar May 30 '21 12:05 uzair004

@uzair004 it's open-source, so I understand your PR is welcome.

christian-hawk avatar Jun 19 '21 18:06 christian-hawk

@uzair004 it's open-source, so I understand your PR is welcome There is already a PR to solve the problem but it's not merged yet, it's been more then 2 years

uzair004 avatar Jun 20 '21 01:06 uzair004