Skip to content

Commit 583fefd

Browse files
committed
Migrate from axios to Nodejs's builtin fetch
1 parent a2aa276 commit 583fefd

File tree

6 files changed

+618
-485
lines changed

6 files changed

+618
-485
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,6 @@ Required to run the project before your modifications
472472
| @octokit/rest | GitHub API library. |
473473
| @passport-js/passport-twitter | X (Twitter) login support (OAuth 2). |
474474
| @popperjs/core | Frontend js library for poppers and tooltips. |
475-
| axios | HTTP client. |
476475
| bootstrap | CSS Framework. |
477476
| bootstrap-social | Social buttons library. |
478477
| chart.js | Frontend js library for creating charts. |

config/passport.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const crypto = require('crypto');
22
const passport = require('passport');
33
const refresh = require('passport-oauth2-refresh');
4-
const axios = require('axios');
54
const { Strategy: LocalStrategy } = require('passport-local');
65
const { Strategy: FacebookStrategy } = require('passport-facebook');
76
const { Strategy: TwitterStrategy } = require('@passport-js/passport-twitter');
@@ -587,12 +586,18 @@ passport.use(
587586
}
588587

589588
const userInfoURL = 'https://api.tumblr.com/v2/user/info';
590-
const response = await axios.get(userInfoURL, {
589+
const response = await fetch(userInfoURL, {
591590
headers: { Authorization: getTumblrAuthHeader(userInfoURL, 'GET') },
592591
});
593592

593+
if (!response.ok) {
594+
throw new Error(`HTTP error! status: ${response.status}`);
595+
}
596+
597+
const data = await response.json();
598+
594599
// Extract user info from the API response
595-
const tumblrUser = response.data.response.user;
600+
const tumblrUser = data.response.user;
596601
if (!user.tumblr) {
597602
user.tumblr = tumblrUser.name; // Save Tumblr username
598603
}
@@ -646,8 +651,12 @@ passport.use(
646651
user.steam = steamId;
647652
user.tokens.push({ kind: 'steam', accessToken: steamId });
648653
try {
649-
const res = await axios.get(profileURL);
650-
const profileData = res.data.response.players[0];
654+
const response = await fetch(profileURL);
655+
if (!response.ok) {
656+
throw new Error(`HTTP error! status: ${response.status}`);
657+
}
658+
const data = await response.json();
659+
const profileData = data.response.players[0];
651660
user.profile.name = user.profile.name || profileData.personaname;
652661
user.profile.picture = user.profile.picture || profileData.avatarmedium;
653662
await user.save();
@@ -659,7 +668,11 @@ passport.use(
659668
}
660669
} else {
661670
try {
662-
const { data } = await axios.get(profileURL);
671+
const response = await fetch(profileURL);
672+
if (!response.ok) {
673+
throw new Error(`HTTP error! status: ${response.status}`);
674+
}
675+
const data = await response.json();
663676
const profileData = data.response.players[0];
664677
const user = new User();
665678
user.steam = steamId;
@@ -701,12 +714,15 @@ const pinterestStrategyConfig = new OAuth2Strategy(
701714
try {
702715
const user = await User.findById(req.user._id);
703716
if (!user.pinterest) {
704-
const pinterestUserResponse = await axios.get('https://api.pinterest.com/v5/user_account', {
717+
const pinterestUserResponse = await fetch('https://api.pinterest.com/v5/user_account', {
705718
headers: {
706719
Authorization: `Bearer ${accessToken}`,
707720
},
708721
});
709-
const pinterestUser = pinterestUserResponse.data;
722+
if (!pinterestUserResponse.ok) {
723+
throw new Error(`HTTP error! status: ${pinterestUserResponse.status}`);
724+
}
725+
const pinterestUser = await pinterestUserResponse.json();
710726
user.pinterest = pinterestUser.id;
711727
if (pinterestUser.website_url) {
712728
user.profile.website = pinterestUser.website_url;

0 commit comments

Comments
 (0)