From c1c23a0b999bba595fa9053a55e6016be4550b95 Mon Sep 17 00:00:00 2001 From: Peter Blazejewicz Date: Fri, 5 Jan 2018 22:30:54 +0100 Subject: [PATCH] Replace passport-local definition file with @types/passport-local This commit: - use @types/passport-local - removes custom definition file - updates implementation to use correct interface from @types/passport-local Thanks! --- package.json | 1 + src/controllers/user.ts | 4 +-- src/types/passport-local.d.ts | 48 ----------------------------------- 3 files changed, 3 insertions(+), 50 deletions(-) delete mode 100644 src/types/passport-local.d.ts diff --git a/package.json b/package.json index fa108a4..1d1344a 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "@types/nodemailer": "^1.3.32", "@types/passport": "^0.3.3", "@types/passport-facebook": "^2.1.3", + "@types/passport-local": "^1.0.32", "@types/request": "^2.0.9", "@types/supertest": "^2.0.4", "@types/shelljs": "^0.7.7", diff --git a/src/controllers/user.ts b/src/controllers/user.ts index b9bcdb8..d8b3e8b 100644 --- a/src/controllers/user.ts +++ b/src/controllers/user.ts @@ -4,7 +4,7 @@ import * as nodemailer from "nodemailer"; import * as passport from "passport"; import { default as User, UserModel, AuthToken } from "../models/User"; import { Request, Response, NextFunction } from "express"; -import { LocalStrategyInfo } from "passport-local"; +import { IVerifyOptions } from "passport-local"; import { WriteError } from "mongodb"; const request = require("express-validator"); @@ -38,7 +38,7 @@ export let postLogin = (req: Request, res: Response, next: NextFunction) => { return res.redirect("/login"); } - passport.authenticate("local", (err: Error, user: UserModel, info: LocalStrategyInfo) => { + passport.authenticate("local", (err: Error, user: UserModel, info: IVerifyOptions) => { if (err) { return next(err); } if (!user) { req.flash("errors", info.message); diff --git a/src/types/passport-local.d.ts b/src/types/passport-local.d.ts deleted file mode 100644 index 1d63374..0000000 --- a/src/types/passport-local.d.ts +++ /dev/null @@ -1,48 +0,0 @@ -// Type definitions for passport-local 1.0.0 -// Project: https://github.com/jaredhanson/passport-local -// Definitions by: Maxime LUCE -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -/// - - - -import passport = require("passport"); -import express = require("express"); - -interface IStrategyOptions { - usernameField?: string; - passwordField?: string; - passReqToCallback?: boolean; -} - -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; -} - -declare class Strategy implements passport.Strategy { - constructor(options: IStrategyOptionsWithRequest, verify: VerifyFunctionWithRequest); - constructor(options: IStrategyOptions, verify: VerifyFunction); - constructor(verify: VerifyFunction); - - name: string; - authenticate: (req: express.Request, options?: Object) => void; -} - -interface LocalStrategyInfo { - message: string; -} \ No newline at end of file