Skip to content

Commit fa22bb2

Browse files
committed
refactor with async await
1 parent 8fd6e23 commit fa22bb2

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

server/services/passport.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,15 @@ passport.use(
2323
callbackURL: '/auth/google/callback',
2424
proxy: true
2525
},
26-
(accessToken, refreshToken, profile, done) => {
27-
User.findOne({ googleId: profile.id }).then(existingUser => {
28-
if (existingUser) {
29-
// we already have a record with the given profile ID
30-
done(null, existingUser);
31-
} else {
32-
// we don't have a user record with this ID, make a new record!
33-
new User({ googleId: profile.id })
34-
.save()
35-
.then(user => done(null, user));
36-
}
37-
});
26+
async (accessToken, refreshToken, profile, done) => {
27+
const existingUser = await User.findOne({ googleId: profile.id });
28+
29+
if (existingUser) {
30+
return done(null, existingUser);
31+
}
32+
33+
const user = await new User({ googleId: profile.id }).save();
34+
done(null, user);
3835
}
3936
)
4037
);

0 commit comments

Comments
 (0)