Skip to content

Commit 3a0121f

Browse files
committed
lib/strategy: Add failWithError support
The failWithError option tells the strategy to not fail but pass instead when authentication fails. This commit makes passport-jwt respect this setting.
1 parent 96a6e55 commit 3a0121f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/strategy.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ JwtStrategy.prototype.authenticate = function(req, options) {
9393
var token = self._jwtFromRequest(req);
9494

9595
if (!token) {
96-
return self.fail(new Error("No auth token"));
96+
if (options.failWithError !== false) {
97+
return self.fail(new Error("No auth token"));
98+
} else {
99+
return self.pass();
100+
}
97101
}
98102

99103
this._secretOrKeyProvider(req, token, function(secretOrKeyError, secretOrKey) {
@@ -110,7 +114,11 @@ JwtStrategy.prototype.authenticate = function(req, options) {
110114
if(err) {
111115
return self.error(err);
112116
} else if (!user) {
113-
return self.fail(info);
117+
if (options.failWithError !== false) {
118+
return self.fail(info);
119+
} else {
120+
return self.pass();
121+
}
114122
} else {
115123
return self.success(user, info);
116124
}

0 commit comments

Comments
 (0)