fixed passport-local typings to allow for two different verify functions, added test

This commit is contained in:
Will Johnston
2015-04-13 18:24:43 -05:00
parent 1711941290
commit 1565c89727
2 changed files with 31 additions and 0 deletions
+20
View File
@@ -44,6 +44,26 @@ passport.use(new local.Strategy(function (username, password, done) {
});
}));
passport.use(new local.Strategy({
passReqToCallback: true
}, function (req, username, password, done) {
User.findOne({ username: username }, function (err, user) {
if (err) {
return done(err);
}
if (!user) {
return done(null, false);
}
if (!user.verifyPassword(password)) {
return done(null, false);
}
return done(null, user);
});
}));
// Sample from https://github.com/jaredhanson/passport-local#authenticate-requests
var app = express();
app.post('/login',
+11
View File
@@ -15,15 +15,26 @@ declare module 'passport-local' {
passwordField?: string;
}
interface IStrategyOptionsWithRequest {
usernameField?: string;
passwordField?: string;
passReqToCallback: boolean;
}
interface IVerifyOptions {
message: string;
}
interface VerifyFunctionWithRequest {
(req: express.Request, username: string, password: string, done: (error: any, user?: any, options?: IVerifyOptions) => void): void;
}
interface VerifyFunction {
(username: string, password: string, done: (error: any, user?: any, options?: IVerifyOptions) => void): void;
}
class Strategy implements passport.Strategy {
constructor(options: IStrategyOptionsWithRequest, verify: VerifyFunctionWithRequest);
constructor(options: IStrategyOptions, verify: VerifyFunction);
constructor(verify: VerifyFunction);