From c828b3a66d68271233085725e9f9d66000a0b49c Mon Sep 17 00:00:00 2001 From: Gray Strider Date: Mon, 30 Sep 2019 12:13:34 +1100 Subject: [PATCH 1/3] Consolidate repeating types, augment express.Request with User model Update User model update "any" types to more precise --- src/config/passport.ts | 20 ++++----- src/controllers/api.ts | 14 +++--- src/controllers/user.ts | 54 ++++++++++++------------ src/models/User.ts | 7 ++- src/types/express-request-with-user.d.ts | 14 ++++++ 5 files changed, 63 insertions(+), 46 deletions(-) create mode 100644 src/types/express-request-with-user.d.ts diff --git a/src/config/passport.ts b/src/config/passport.ts index c116d243..fc808e80 100644 --- a/src/config/passport.ts +++ b/src/config/passport.ts @@ -5,7 +5,7 @@ import _ from "lodash"; // import { User, UserType } from '../models/User'; import { User, UserDocument } from "../models/User"; -import { Request, Response, NextFunction } from "express"; +import {genericExpressMethod} from "express-request-with-user"; const LocalStrategy = passportLocal.Strategy; const FacebookStrategy = passportFacebook.Strategy; @@ -25,12 +25,12 @@ passport.deserializeUser((id, done) => { * Sign in using Email and Password. */ passport.use(new LocalStrategy({ usernameField: "email" }, (email, password, done) => { - User.findOne({ email: email.toLowerCase() }, (err, user: any) => { + User.findOne({ email: email.toLowerCase() }, (err, user: UserDocument) => { if (err) { return done(err); } if (!user) { return done(undefined, false, { message: `Email ${email} not found.` }); } - user.comparePassword(password, (err: Error, isMatch: boolean) => { + user.comparePassword(password, (err, isMatch) => { if (err) { return done(err); } if (isMatch) { return done(undefined, user); @@ -66,7 +66,7 @@ passport.use(new FacebookStrategy({ callbackURL: "/auth/facebook/callback", profileFields: ["name", "email", "link", "locale", "timezone"], passReqToCallback: true -}, (req: any, accessToken, refreshToken, profile, done) => { +}, (req, accessToken, refreshToken, profile, done) => { if (req.user) { User.findOne({ facebook: profile.id }, (err, existingUser) => { if (err) { return done(err); } @@ -74,7 +74,7 @@ passport.use(new FacebookStrategy({ req.flash("errors", { msg: "There is already a Facebook account that belongs to you. Sign in with that account or delete it, then link it with your current account." }); done(err); } else { - User.findById(req.user.id, (err, user: any) => { + User.findById(req.user.id, (err, user) => { if (err) { return done(err); } user.facebook = profile.id; user.tokens.push({ kind: "facebook", accessToken }); @@ -100,7 +100,7 @@ passport.use(new FacebookStrategy({ req.flash("errors", { msg: "There is already an account using this email address. Sign in to that account and link it with Facebook manually from Account Settings." }); done(err); } else { - const user: any = new User(); + const user: UserDocument = new User(); user.email = profile._json.email; user.facebook = profile.id; user.tokens.push({ kind: "facebook", accessToken }); @@ -120,7 +120,7 @@ passport.use(new FacebookStrategy({ /** * Login Required middleware. */ -export const isAuthenticated = (req: Request, res: Response, next: NextFunction) => { +export const isAuthenticated: genericExpressMethod = (req, res, next) => { if (req.isAuthenticated()) { return next(); } @@ -130,11 +130,11 @@ export const isAuthenticated = (req: Request, res: Response, next: NextFunction) /** * Authorization Required middleware. */ -export const isAuthorized = (req: Request, res: Response, next: NextFunction) => { +export const isAuthorized: genericExpressMethod = (req, res, next) => { const provider = req.path.split("/").slice(-1)[0]; - const user = req.user as UserDocument; - if (_.find(user.tokens, { kind: provider })) { + // const user = req.user as UserDocument; + if (_.find(req.user.tokens, { kind: provider })) { next(); } else { res.redirect(`/auth/${provider}`); diff --git a/src/controllers/api.ts b/src/controllers/api.ts index d5816518..9f4b5fd7 100644 --- a/src/controllers/api.ts +++ b/src/controllers/api.ts @@ -1,8 +1,6 @@ -"use strict"; - import graph from "fbgraph"; -import { Response, Request, NextFunction } from "express"; -import { UserDocument } from "../models/User"; +import { Response, Request } from "express"; +import {genericExpressMethod} from "express-request-with-user"; /** @@ -19,11 +17,11 @@ export const getApi = (req: Request, res: Response) => { * GET /api/facebook * Facebook API example. */ -export const getFacebook = (req: Request, res: Response, next: NextFunction) => { - const user = req.user as UserDocument; - const token = user.tokens.find((token: any) => token.kind === "facebook"); +export const getFacebook: genericExpressMethod = (req, res, next) => { + // const user = req.user /*as UserDocument*/; + const token = req.user.tokens.find(token => token.kind === "facebook"); graph.setAccessToken(token.accessToken); - graph.get(`${user.facebook}?fields=id,name,email,first_name,last_name,gender,link,locale,timezone`, (err: Error, results: graph.FacebookUser) => { + graph.get(`${req.user.facebook}?fields=id,name,email,first_name,last_name,gender,link,locale,timezone`, (err: Error, results: graph.FacebookUser) => { if (err) { return next(err); } res.render("api/facebook", { title: "Facebook API", diff --git a/src/controllers/user.ts b/src/controllers/user.ts index fd1bd813..764babe0 100644 --- a/src/controllers/user.ts +++ b/src/controllers/user.ts @@ -2,12 +2,13 @@ import async from "async"; import crypto from "crypto"; import nodemailer from "nodemailer"; import passport from "passport"; -import { User, UserDocument, AuthToken } from "../models/User"; -import { Request, Response, NextFunction } from "express"; -import { IVerifyOptions } from "passport-local"; -import { WriteError } from "mongodb"; -import { check, sanitize, validationResult } from "express-validator"; +import {AuthToken, User, UserDocument} from "../models/User"; +import {Request, Response} from "express"; +import {IVerifyOptions} from "passport-local"; +import {WriteError} from "mongodb"; +import {check, sanitize, validationResult} from "express-validator"; import "../config/passport"; +import {genericExpressMethod} from "express-request-with-user"; /** * GET /login @@ -26,7 +27,8 @@ export const getLogin = (req: Request, res: Response) => { * POST /login * Sign in using email and password. */ -export const postLogin = (req: Request, res: Response, next: NextFunction) => { + +export const postLogin: genericExpressMethod = (req, res, next) => { check("email", "Email is not valid").isEmail(); check("password", "Password cannot be blank").isLength({min: 1}); // eslint-disable-next-line @typescript-eslint/camelcase @@ -79,7 +81,7 @@ export const getSignup = (req: Request, res: Response) => { * POST /signup * Create a new local account. */ -export const postSignup = (req: Request, res: Response, next: NextFunction) => { +export const postSignup: genericExpressMethod = (req, res, next) => { check("email", "Email is not valid").isEmail(); check("password", "Password must be at least 4 characters long").isLength({ min: 4 }); check("confirmPassword", "Passwords do not match").equals(req.body.password); @@ -130,7 +132,7 @@ export const getAccount = (req: Request, res: Response) => { * POST /account/profile * Update profile information. */ -export const postUpdateProfile = (req: Request, res: Response, next: NextFunction) => { +export const postUpdateProfile: genericExpressMethod = (req, res, next) => { check("email", "Please enter a valid email address.").isEmail(); // eslint-disable-next-line @typescript-eslint/camelcase sanitize("email").normalizeEmail({ gmail_remove_dots: false }); @@ -142,8 +144,8 @@ export const postUpdateProfile = (req: Request, res: Response, next: NextFunctio return res.redirect("/account"); } - const user = req.user as UserDocument; - User.findById(user.id, (err, user: UserDocument) => { + // const user = req.user as UserDocument; + User.findById(req.user.id, (err, user) => { if (err) { return next(err); } user.email = req.body.email || ""; user.profile.name = req.body.name || ""; @@ -168,7 +170,7 @@ export const postUpdateProfile = (req: Request, res: Response, next: NextFunctio * POST /account/password * Update current password. */ -export const postUpdatePassword = (req: Request, res: Response, next: NextFunction) => { +export const postUpdatePassword: genericExpressMethod = (req, res, next) => { check("password", "Password must be at least 4 characters long").isLength({ min: 4 }); check("confirmPassword", "Passwords do not match").equals(req.body.password); @@ -179,8 +181,8 @@ export const postUpdatePassword = (req: Request, res: Response, next: NextFuncti return res.redirect("/account"); } - const user = req.user as UserDocument; - User.findById(user.id, (err, user: UserDocument) => { + // const user = req.user as UserDocument; + User.findById(req.user.id, (err, user) => { if (err) { return next(err); } user.password = req.body.password; user.save((err: WriteError) => { @@ -195,9 +197,9 @@ export const postUpdatePassword = (req: Request, res: Response, next: NextFuncti * POST /account/delete * Delete user account. */ -export const postDeleteAccount = (req: Request, res: Response, next: NextFunction) => { - const user = req.user as UserDocument; - User.remove({ _id: user.id }, (err) => { +export const postDeleteAccount: genericExpressMethod = (req, res, next) => { + // const user = req.user as UserDocument; + User.remove({ _id: req.user.id }, (err) => { if (err) { return next(err); } req.logout(); req.flash("info", { msg: "Your account has been deleted." }); @@ -209,12 +211,12 @@ export const postDeleteAccount = (req: Request, res: Response, next: NextFunctio * GET /account/unlink/:provider * Unlink OAuth provider. */ -export const getOauthUnlink = (req: Request, res: Response, next: NextFunction) => { +export const getOauthUnlink: genericExpressMethod = (req, res, next) => { const provider = req.params.provider; - const user = req.user as UserDocument; - User.findById(user.id, (err, user: any) => { + // const user = req.user as UserDocument; + User.findById(req.user.id, (err, user) => { if (err) { return next(err); } - user[provider] = undefined; + // user[provider] = undefined; user.tokens = user.tokens.filter((token: AuthToken) => token.kind !== provider); user.save((err: WriteError) => { if (err) { return next(err); } @@ -228,7 +230,7 @@ export const getOauthUnlink = (req: Request, res: Response, next: NextFunction) * GET /reset/:token * Reset Password page. */ -export const getReset = (req: Request, res: Response, next: NextFunction) => { +export const getReset: genericExpressMethod = (req, res, next) => { if (req.isAuthenticated()) { return res.redirect("/"); } @@ -251,7 +253,7 @@ export const getReset = (req: Request, res: Response, next: NextFunction) => { * POST /reset/:token * Process the reset password request. */ -export const postReset = (req: Request, res: Response, next: NextFunction) => { +export const postReset: genericExpressMethod = (req, res, next) => { check("password", "Password must be at least 4 characters long.").isLength({ min: 4 }); check("confirm", "Passwords must match.").equals(req.body.password); @@ -267,7 +269,7 @@ export const postReset = (req: Request, res: Response, next: NextFunction) => { User .findOne({ passwordResetToken: req.params.token }) .where("passwordResetExpires").gt(Date.now()) - .exec((err, user: any) => { + .exec((err, user) => { if (err) { return next(err); } if (!user) { req.flash("errors", { msg: "Password reset token is invalid or has expired." }); @@ -326,7 +328,7 @@ export const getForgot = (req: Request, res: Response) => { * POST /forgot * Create a random token, then the send user an email with a reset link. */ -export const postForgot = (req: Request, res: Response, next: NextFunction) => { +export const postForgot: genericExpressMethod = (req, res, next) => { check("email", "Please enter a valid email address.").isEmail(); // eslint-disable-next-line @typescript-eslint/camelcase sanitize("email").normalizeEmail({ gmail_remove_dots: false }); @@ -346,14 +348,14 @@ export const postForgot = (req: Request, res: Response, next: NextFunction) => { }); }, function setRandomToken(token: AuthToken, done: Function) { - User.findOne({ email: req.body.email }, (err, user: any) => { + User.findOne({ email: req.body.email }, (err, user) => { if (err) { return done(err); } if (!user) { req.flash("errors", { msg: "Account with that email address does not exist." }); return res.redirect("/forgot"); } user.passwordResetToken = token; - user.passwordResetExpires = Date.now() + 3600000; // 1 hour + user.passwordResetExpires = new Date(Date.now() + 3600000); // 1 hour user.save((err: WriteError) => { done(err, token, user); }); diff --git a/src/models/User.ts b/src/models/User.ts index 0157e6fa..7753a7ce 100644 --- a/src/models/User.ts +++ b/src/models/User.ts @@ -5,7 +5,8 @@ import mongoose from "mongoose"; export type UserDocument = mongoose.Document & { email: string; password: string; - passwordResetToken: string; + passwordResetToken: AuthToken; + // passwordResetToken: string; passwordResetExpires: Date; facebook: string; @@ -21,9 +22,11 @@ export type UserDocument = mongoose.Document & { comparePassword: comparePasswordFunction; gravatar: (size: number) => string; + + // [provider: string]: any; }; -type comparePasswordFunction = (candidatePassword: string, cb: (err: any, isMatch: any) => {}) => void; +type comparePasswordFunction = (candidatePassword: string, cb: (err: Error, isMatch: boolean) => void) => void; export interface AuthToken { accessToken: string; diff --git a/src/types/express-request-with-user.d.ts b/src/types/express-request-with-user.d.ts new file mode 100644 index 00000000..20333e73 --- /dev/null +++ b/src/types/express-request-with-user.d.ts @@ -0,0 +1,14 @@ +/// + +import {UserDocument} from "../models/User"; +import {NextFunction, Request, Response} from "express"; + +declare module 'express' { + export interface User extends UserDocument {} + export interface Request { + user?: User; + } +} + +/** To avoid duplication */ +export type genericExpressMethod = (req: Request, res: Response, next: NextFunction) => void \ No newline at end of file From ba08d2190948c4b002d2e35b83ea973c90fc846f Mon Sep 17 00:00:00 2001 From: Gray Strider Date: Tue, 1 Oct 2019 13:30:36 +1100 Subject: [PATCH 2/3] Removed comments, removed genericExpressMethod --- src/config/passport.ts | 10 ++----- src/controllers/api.ts | 6 ++-- src/controllers/user.ts | 35 ++++++++++-------------- src/models/User.ts | 3 -- src/types/express-request-with-user.d.ts | 7 +---- 5 files changed, 20 insertions(+), 41 deletions(-) diff --git a/src/config/passport.ts b/src/config/passport.ts index fc808e80..3d0a231a 100644 --- a/src/config/passport.ts +++ b/src/config/passport.ts @@ -2,11 +2,8 @@ import passport from "passport"; import passportLocal from "passport-local"; import passportFacebook from "passport-facebook"; import _ from "lodash"; - -// import { User, UserType } from '../models/User'; import { User, UserDocument } from "../models/User"; -import {genericExpressMethod} from "express-request-with-user"; - +import { Request, Response, NextFunction } from "express"; const LocalStrategy = passportLocal.Strategy; const FacebookStrategy = passportFacebook.Strategy; @@ -120,7 +117,7 @@ passport.use(new FacebookStrategy({ /** * Login Required middleware. */ -export const isAuthenticated: genericExpressMethod = (req, res, next) => { +export const isAuthenticated = (req: Request, res: Response, next: NextFunction) => { if (req.isAuthenticated()) { return next(); } @@ -130,10 +127,9 @@ export const isAuthenticated: genericExpressMethod = (req, res, next) => { /** * Authorization Required middleware. */ -export const isAuthorized: genericExpressMethod = (req, res, next) => { +export const isAuthorized = (req: Request, res: Response, next: NextFunction) => { const provider = req.path.split("/").slice(-1)[0]; - // const user = req.user as UserDocument; if (_.find(req.user.tokens, { kind: provider })) { next(); } else { diff --git a/src/controllers/api.ts b/src/controllers/api.ts index 9f4b5fd7..284bd56d 100644 --- a/src/controllers/api.ts +++ b/src/controllers/api.ts @@ -1,6 +1,5 @@ import graph from "fbgraph"; -import { Response, Request } from "express"; -import {genericExpressMethod} from "express-request-with-user"; +import { Response, Request, NextFunction } from "express"; /** @@ -17,8 +16,7 @@ export const getApi = (req: Request, res: Response) => { * GET /api/facebook * Facebook API example. */ -export const getFacebook: genericExpressMethod = (req, res, next) => { - // const user = req.user /*as UserDocument*/; +export const getFacebook = (req: Request, res: Response, next: NextFunction) => { const token = req.user.tokens.find(token => token.kind === "facebook"); graph.setAccessToken(token.accessToken); graph.get(`${req.user.facebook}?fields=id,name,email,first_name,last_name,gender,link,locale,timezone`, (err: Error, results: graph.FacebookUser) => { diff --git a/src/controllers/user.ts b/src/controllers/user.ts index 764babe0..72c716fb 100644 --- a/src/controllers/user.ts +++ b/src/controllers/user.ts @@ -2,13 +2,12 @@ import async from "async"; import crypto from "crypto"; import nodemailer from "nodemailer"; import passport from "passport"; -import {AuthToken, User, UserDocument} from "../models/User"; -import {Request, Response} from "express"; -import {IVerifyOptions} from "passport-local"; -import {WriteError} from "mongodb"; -import {check, sanitize, validationResult} from "express-validator"; +import { User, UserDocument, AuthToken } from "../models/User"; +import { Request, Response, NextFunction } from "express"; +import { IVerifyOptions } from "passport-local"; +import { WriteError } from "mongodb"; +import { check, sanitize, validationResult } from "express-validator"; import "../config/passport"; -import {genericExpressMethod} from "express-request-with-user"; /** * GET /login @@ -27,8 +26,7 @@ export const getLogin = (req: Request, res: Response) => { * POST /login * Sign in using email and password. */ - -export const postLogin: genericExpressMethod = (req, res, next) => { +export const postLogin = (req: Request, res: Response, next: NextFunction) => { check("email", "Email is not valid").isEmail(); check("password", "Password cannot be blank").isLength({min: 1}); // eslint-disable-next-line @typescript-eslint/camelcase @@ -81,7 +79,7 @@ export const getSignup = (req: Request, res: Response) => { * POST /signup * Create a new local account. */ -export const postSignup: genericExpressMethod = (req, res, next) => { +export const postSignup = (req: Request, res: Response, next: NextFunction) => { check("email", "Email is not valid").isEmail(); check("password", "Password must be at least 4 characters long").isLength({ min: 4 }); check("confirmPassword", "Passwords do not match").equals(req.body.password); @@ -132,7 +130,7 @@ export const getAccount = (req: Request, res: Response) => { * POST /account/profile * Update profile information. */ -export const postUpdateProfile: genericExpressMethod = (req, res, next) => { +export const postUpdateProfile = (req: Request, res: Response, next: NextFunction) => { check("email", "Please enter a valid email address.").isEmail(); // eslint-disable-next-line @typescript-eslint/camelcase sanitize("email").normalizeEmail({ gmail_remove_dots: false }); @@ -144,7 +142,6 @@ export const postUpdateProfile: genericExpressMethod = (req, res, next) => { return res.redirect("/account"); } - // const user = req.user as UserDocument; User.findById(req.user.id, (err, user) => { if (err) { return next(err); } user.email = req.body.email || ""; @@ -170,7 +167,7 @@ export const postUpdateProfile: genericExpressMethod = (req, res, next) => { * POST /account/password * Update current password. */ -export const postUpdatePassword: genericExpressMethod = (req, res, next) => { +export const postUpdatePassword = (req: Request, res: Response, next: NextFunction) => { check("password", "Password must be at least 4 characters long").isLength({ min: 4 }); check("confirmPassword", "Passwords do not match").equals(req.body.password); @@ -181,7 +178,6 @@ export const postUpdatePassword: genericExpressMethod = (req, res, next) => { return res.redirect("/account"); } - // const user = req.user as UserDocument; User.findById(req.user.id, (err, user) => { if (err) { return next(err); } user.password = req.body.password; @@ -197,8 +193,7 @@ export const postUpdatePassword: genericExpressMethod = (req, res, next) => { * POST /account/delete * Delete user account. */ -export const postDeleteAccount: genericExpressMethod = (req, res, next) => { - // const user = req.user as UserDocument; +export const postDeleteAccount = (req: Request, res: Response, next: NextFunction) => { User.remove({ _id: req.user.id }, (err) => { if (err) { return next(err); } req.logout(); @@ -211,12 +206,10 @@ export const postDeleteAccount: genericExpressMethod = (req, res, next) => { * GET /account/unlink/:provider * Unlink OAuth provider. */ -export const getOauthUnlink: genericExpressMethod = (req, res, next) => { +export const getOauthUnlink = (req: Request, res: Response, next: NextFunction) => { const provider = req.params.provider; - // const user = req.user as UserDocument; User.findById(req.user.id, (err, user) => { if (err) { return next(err); } - // user[provider] = undefined; user.tokens = user.tokens.filter((token: AuthToken) => token.kind !== provider); user.save((err: WriteError) => { if (err) { return next(err); } @@ -230,7 +223,7 @@ export const getOauthUnlink: genericExpressMethod = (req, res, next) => { * GET /reset/:token * Reset Password page. */ -export const getReset: genericExpressMethod = (req, res, next) => { +export const getReset = (req: Request, res: Response, next: NextFunction) => { if (req.isAuthenticated()) { return res.redirect("/"); } @@ -253,7 +246,7 @@ export const getReset: genericExpressMethod = (req, res, next) => { * POST /reset/:token * Process the reset password request. */ -export const postReset: genericExpressMethod = (req, res, next) => { +export const postReset = (req: Request, res: Response, next: NextFunction) => { check("password", "Password must be at least 4 characters long.").isLength({ min: 4 }); check("confirm", "Passwords must match.").equals(req.body.password); @@ -328,7 +321,7 @@ export const getForgot = (req: Request, res: Response) => { * POST /forgot * Create a random token, then the send user an email with a reset link. */ -export const postForgot: genericExpressMethod = (req, res, next) => { +export const postForgot = (req: Request, res: Response, next: NextFunction) => { check("email", "Please enter a valid email address.").isEmail(); // eslint-disable-next-line @typescript-eslint/camelcase sanitize("email").normalizeEmail({ gmail_remove_dots: false }); diff --git a/src/models/User.ts b/src/models/User.ts index 7753a7ce..94cccf0b 100644 --- a/src/models/User.ts +++ b/src/models/User.ts @@ -6,7 +6,6 @@ export type UserDocument = mongoose.Document & { email: string; password: string; passwordResetToken: AuthToken; - // passwordResetToken: string; passwordResetExpires: Date; facebook: string; @@ -22,8 +21,6 @@ export type UserDocument = mongoose.Document & { comparePassword: comparePasswordFunction; gravatar: (size: number) => string; - - // [provider: string]: any; }; type comparePasswordFunction = (candidatePassword: string, cb: (err: Error, isMatch: boolean) => void) => void; diff --git a/src/types/express-request-with-user.d.ts b/src/types/express-request-with-user.d.ts index 20333e73..25051458 100644 --- a/src/types/express-request-with-user.d.ts +++ b/src/types/express-request-with-user.d.ts @@ -1,5 +1,3 @@ -/// - import {UserDocument} from "../models/User"; import {NextFunction, Request, Response} from "express"; @@ -8,7 +6,4 @@ declare module 'express' { export interface Request { user?: User; } -} - -/** To avoid duplication */ -export type genericExpressMethod = (req: Request, res: Response, next: NextFunction) => void \ No newline at end of file +} \ No newline at end of file From 11b33650e278adb5fddaabdc3bb976e92913d489 Mon Sep 17 00:00:00 2001 From: Gray Strider Date: Wed, 2 Oct 2019 00:22:42 +1100 Subject: [PATCH 3/3] Update EsLint rules: no-explicit-any: warning, no-inferrable-types: warning except for parameters update (remove) "any" types --- .eslintrc | 8 ++++++-- src/config/passport.ts | 2 +- src/types/express-request-with-user.d.ts | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.eslintrc b/.eslintrc index b2eef2e2..78f667ab 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,7 +9,11 @@ "semi": ["error", "always"], "quotes": ["error", "double"], "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-inferrable-types": "off" + "@typescript-eslint/no-explicit-any": 1, + "@typescript-eslint/no-inferrable-types": [ + "warn", { + "ignoreParameters": true + } + ] } } diff --git a/src/config/passport.ts b/src/config/passport.ts index 3d0a231a..ec491a54 100644 --- a/src/config/passport.ts +++ b/src/config/passport.ts @@ -7,7 +7,7 @@ import { Request, Response, NextFunction } from "express"; const LocalStrategy = passportLocal.Strategy; const FacebookStrategy = passportFacebook.Strategy; -passport.serializeUser((user, done) => { +passport.serializeUser((user: UserDocument, done) => { done(undefined, user.id); }); diff --git a/src/types/express-request-with-user.d.ts b/src/types/express-request-with-user.d.ts index 25051458..9ea0b09d 100644 --- a/src/types/express-request-with-user.d.ts +++ b/src/types/express-request-with-user.d.ts @@ -1,5 +1,5 @@ import {UserDocument} from "../models/User"; -import {NextFunction, Request, Response} from "express"; +import {Request} from "express"; declare module 'express' { export interface User extends UserDocument {}