Skip to content

Commit

Permalink
Async/await feature fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Zsargó Dávid committed Dec 3, 2018
1 parent 3215b67 commit e857455
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions config/passport-oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,26 @@ passport.deserializeUser((id, done) => {

passport.use(
new OAuth2Strategy(keys.oauth2,
(async (accessToken, refreshToken, profile, done) => {
((accessToken, refreshToken, profile, done) => {
const options = {
url: keys.profileUrl,
headers: {
Authorization: `Bearer ${accessToken}`,
},
};
const ProfilePromise = new Promise((resolve, reject) => {

new Promise((resolve, reject) => {
request(options, (error, response, body) => {
if (!error && response.statusCode === 200) {
resolve(JSON.parse(body));
} else {
reject(error);
}
});
});

try {
const fetchedProfile = await ProfilePromise;
}).then((fetchedProfile) => {
profileStorage.save(fetchedProfile);
done(null, fetchedProfile);
} catch (error) {
done(error, null);
}
}, error => done(error, null));
})),
);

Expand Down

0 comments on commit e857455

Please sign in to comment.