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:
Troy Gerwien
2014-04-06 11:59:54 +08:00
parent b9c60cc42b
commit ce0be7b9f5
2 changed files with 14 additions and 12 deletions
+4 -4
View File
@@ -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');
+10 -8
View File
@@ -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;
}
}