mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
fixed passport-local typings to allow for two different verify functions, added test
This commit is contained in:
@@ -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',
|
||||
|
||||
Vendored
+11
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user