fix: support not logged in users

This commit is contained in:
Wyatt Johnson
2018-07-20 16:19:33 -06:00
parent bdd4bfc272
commit 2c1111109a
@@ -156,19 +156,20 @@ export class JWTStrategy extends Strategy {
}
public authenticate(req: Request) {
// Lookup the token.
const token = extractJWTFromRequest(req);
if (!token) {
// There was no token on the request, so there was no user, so let's mark
// that the strategy was succesfull.
return this.success(null, null);
}
const { tenant } = req;
if (!tenant) {
// TODO: (wyattjoh) return a better error.
return this.error(new Error("tenant not found"));
}
// Lookup the token.
const token = extractJWTFromRequest(req);
if (!token) {
// TODO: (wyattjoh) return a better error.
return this.fail(new Error("no token on request"), 401);
}
jwt.verify(
token,
// Use the secret specified in the configuration.