From 6393a67730cacb098750750a27f46a0a1da42eb0 Mon Sep 17 00:00:00 2001 From: "Braden M. Kelley" Date: Thu, 2 Nov 2017 10:14:40 -0700 Subject: [PATCH] fix (makeen-user): make passport.deserializeUser async deserializeUser should not try to use the UserRepository service without waiting for it --- packages/makeen-user/src/libs/passport.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/makeen-user/src/libs/passport.js b/packages/makeen-user/src/libs/passport.js index 6324830..6e5ec05 100644 --- a/packages/makeen-user/src/libs/passport.js +++ b/packages/makeen-user/src/libs/passport.js @@ -9,15 +9,11 @@ export default ({ jwtSecret }) => { new JwtStrategy( { secretOrKey: jwtSecret, - jwtFromRequest: ExtractJwt.fromExtractors([ - ExtractJwt.fromAuthHeaderWithScheme('Bearer'), - ]), + jwtFromRequest: ExtractJwt.fromExtractors([ExtractJwt.fromAuthHeaderWithScheme('Bearer')]), passReqToCallback: true, }, async (req, id, done) => { - const { UserRepository, AccountRepository, User } = req.app.modules.get( - 'makeen.user', - ); + const { UserRepository, AccountRepository, User } = req.app.modules.get('makeen.user'); try { const user = await UserRepository.findById(objectId(id)); const account = await AccountRepository.findById(user.accountId); @@ -65,11 +61,10 @@ export default ({ jwtSecret }) => { cb(null, user._id.toString()); }); - passport.deserializeUser((req, id, cb) => { - req.app.modules - .get('makeen.user.UserRepository') - .findById(objectId(id)) - .then(user => cb(null, user), cb); + passport.deserializeUser(async (req, id, cb) => { + const { UserRepository } = await req.app.modules.get('makeen.user'); + + UserRepository.findById(objectId(id)).then(user => cb(null, user), cb); }); return passport;