Deserializing a user with passportjs (promise chaining vs async await?)

I'm following a tutorial on passport and am looking at a deserializeUser function:
passport.deserializeUser((userId, done) => {
User.findById(userId)
.then(user => {
done(null, user)
})
.catch(err => done(err));
});
passport.deserializeUser((userId, done) => {
User.findById(userId)
.then(user => {
done(null, user)
})
.catch(err => done(err));
});
But I was wondering if there's any issue with using async await
passport.deserializeUser(async(userId, done) => {
try {
const user = await User.findByPk(userId);
if(user) done(null, user);
} catch(err) {
done(err)
}
})
passport.deserializeUser(async(userId, done) => {
try {
const user = await User.findByPk(userId);
if(user) done(null, user);
} catch(err) {
done(err)
}
})
Can't see anything wrong with it imo, but famous last words 😁
2 Replies
Jochem
Jochem2y ago
nah, that's fine. it's just another way of resolving a promise
JWode
JWode2y ago
Yeah I thought so, but anything security wise gets me a little nervous 😄 thanks
Want results from more Discord servers?
Add your server