From e93f61a3f0a3575ff08c3e3d7280812fe8daedea Mon Sep 17 00:00:00 2001 From: Jerry Ren Date: Wed, 1 Nov 2023 13:24:10 -0400 Subject: [PATCH] Replaced axios with fetch Removed axios from package.json. And replaced axios call with fetch call. --- package.json | 1 - src/controllers/userProfileController.js | 16 +++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 85fb77a4f..1c6b8a5d4 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "@babel/runtime": "^7.10.2", "@sentry/node": "^5.17.0", "async-exit-hook": "^2.0.1", - "axios": "^1.5.1", "babel-plugin-module-resolver": "^5.0.0", "bcryptjs": "^2.4.3", "body-parser": "^1.18.3", diff --git a/src/controllers/userProfileController.js b/src/controllers/userProfileController.js index e32878737..a36b1c065 100644 --- a/src/controllers/userProfileController.js +++ b/src/controllers/userProfileController.js @@ -2,7 +2,7 @@ const moment = require('moment-timezone'); const mongoose = require('mongoose'); const bcrypt = require('bcryptjs'); -const axios = require('axios') +const fetch = require("node-fetch"); const moment_ = require('moment'); const jwt = require('jsonwebtoken'); @@ -142,10 +142,16 @@ const userProfileController = function (UserProfile) { const url = "https://hgn-rest-beta.azurewebsites.net/api/" try { // Log in to Beta login route using provided credentials - let response = await axios.post(url + "login", { - email: email, - password: password - }) + const response = await fetch(url + 'login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ email, password }), + }); + if (!response.ok) { + throw new Error('Invalid credentials'); + } } catch (error) { res.status(400).send({ error: 'The actual email or password you provided is incorrect. Please enter the actual email and password associated with your account in the Main HGN app.',