mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-20 12:00:53 +08:00
amend passport.d.ts
- passport.d.ts has been amended to merge its Request extensions into express's Request interface. - removed now-unnecessary type coercions from passport-test.ts
This commit is contained in:
@@ -7,7 +7,7 @@ import passport = require('passport');
|
||||
class TestStrategy implements passport.Strategy {
|
||||
public name: string = 'test';
|
||||
constructor() {}
|
||||
authenticate(req: passport.Request) {}
|
||||
authenticate(req: express.Request) {}
|
||||
}
|
||||
|
||||
passport.use(new TestStrategy());
|
||||
@@ -33,7 +33,7 @@ app.post('/login',
|
||||
res.redirect('/');
|
||||
});
|
||||
|
||||
app.post('/login', function(req: passport.Request, res: passport.Response, next: (err?: any) => void) {
|
||||
app.post('/login', function(req, res, next) {
|
||||
passport.authenticate('local', function(err, user, info) {
|
||||
if (err) { return next(err) }
|
||||
if (!user) {
|
||||
@@ -47,12 +47,12 @@ app.post('/login', function(req: passport.Request, res: passport.Response, next:
|
||||
})(req, res, next);
|
||||
});
|
||||
|
||||
app.get('/logout', function(req: passport.Request, res: passport.Response) {
|
||||
app.get('/logout', function(req, res) {
|
||||
req.logout();
|
||||
res.redirect('/');
|
||||
});
|
||||
|
||||
function ensureAuthenticated(req: passport.Request, res: passport.Response, next: (err?: any) => void) {
|
||||
function ensureAuthenticated(req: express.Request, res: express.Response, next: (err?: any) => void) {
|
||||
if (req.isAuthenticated()) { return next(); }
|
||||
if (req.isUnauthenticated()) {
|
||||
res.redirect('/login');
|
||||
|
||||
Vendored
+10
-8
@@ -38,7 +38,16 @@ declare module 'passport' {
|
||||
transformAuthInfo(fn: (info: any, done: (err: any, info: any) => void) => void): void;
|
||||
}
|
||||
|
||||
interface Request extends express.Request {
|
||||
interface Strategy {
|
||||
name?: string;
|
||||
authenticate(req: express.Request, options?: Object): void;
|
||||
}
|
||||
}
|
||||
|
||||
declare module Express {
|
||||
export interface Request {
|
||||
|
||||
// These declarations are merged into express's Request type
|
||||
login(user: any, done: (err: any) => void): void;
|
||||
login(user: any, options: Object, done: (err: any) => void): void;
|
||||
logIn(user: any, done: (err: any) => void): void;
|
||||
@@ -50,11 +59,4 @@ declare module 'passport' {
|
||||
isAuthenticated(): boolean;
|
||||
isUnauthenticated(): boolean;
|
||||
}
|
||||
interface Response extends express.Response {}
|
||||
|
||||
interface Strategy {
|
||||
name?: string;
|
||||
authenticate(req: Request, options?: Object): void;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user