Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions packages/makeen-user/src/libs/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for that - modules.get('some-module-name') is synchronous and it returns a map of that module's exports


UserRepository.findById(objectId(id)).then(user => cb(null, user), cb);
});

return passport;
Expand Down