revert: replace axios with fetch

This reverts commit 82f3f6ae0c via PR #41944.
pull/42526/head
Mrugesh Mohapatra 2021-06-16 16:44:32 +05:30
parent e402464304
commit 418287f1e8
No known key found for this signature in database
GPG Key ID: 68BDF41E23F50DD8
9 changed files with 36 additions and 72 deletions

View File

@ -7392,15 +7392,6 @@
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.1.0.tgz",
"integrity": "sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ=="
},
"bindings": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz",
"integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==",
"optional": true,
"requires": {
"file-uri-to-path": "1.0.0"
}
},
"bl": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz",
@ -11337,12 +11328,6 @@
"token-types": "^2.0.0"
}
},
"file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==",
"optional": true
},
"filesize": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/filesize/-/filesize-6.1.0.tgz",
@ -16713,12 +16698,6 @@
"resolved": "https://registry.npmjs.org/name-all-modules-plugin/-/name-all-modules-plugin-1.0.1.tgz",
"integrity": "sha1-Cr+2rYNXGLn7Te8GdOBmV6lUN1w="
},
"nan": {
"version": "2.14.2",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz",
"integrity": "sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==",
"optional": true
},
"nanoid": {
"version": "3.1.23",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.23.tgz",
@ -22746,11 +22725,7 @@
"version": "1.2.13",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz",
"integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==",
"optional": true,
"requires": {
"bindings": "^1.5.0",
"nan": "^2.12.1"
}
"optional": true
},
"glob-parent": {
"version": "3.1.0",

View File

@ -55,6 +55,7 @@
"@reach/router": "1.3.4",
"algoliasearch": "4.9.3",
"assert": "2.0.0",
"axios": "0.21.1",
"babel-plugin-preval": "5.0.0",
"babel-plugin-prismjs": "2.0.1",
"bezier-easing": "2.1.0",

View File

@ -8,7 +8,7 @@ import { putUserAcceptsTerms } from '../utils/ajax';
function* acceptTermsSaga({ payload: quincyEmails }) {
try {
const response = yield call(putUserAcceptsTerms, quincyEmails);
const { data: response } = yield call(putUserAcceptsTerms, quincyEmails);
yield put(acceptTermsComplete(quincyEmails));
yield put(createFlashMessage(response));

View File

@ -16,9 +16,7 @@ function* fetchSessionUser() {
}
try {
const {
user = {},
result = '',
sessionMeta = {}
data: { user = {}, result = '', sessionMeta = {} }
} = yield call(getSessionUser);
const appUser = user[result] || {};
yield put(
@ -32,11 +30,9 @@ function* fetchSessionUser() {
function* fetchOtherUser({ payload: maybeUser = '' }) {
try {
const maybeUserLC = maybeUser.toLowerCase();
const { data } = yield call(getUserProfile, maybeUserLC);
const { entities: { user = {} } = {}, result = '' } = yield call(
getUserProfile,
maybeUserLC
);
const { entities: { user = {} } = {}, result = '' } = data;
const otherUser = user[result] || {};
yield put(
fetchProfileForUserComplete({ user: otherUser, username: result })

View File

@ -8,7 +8,7 @@ import { postReportUser } from '../utils/ajax';
function* reportUserSaga({ payload }) {
try {
const response = yield call(postReportUser, payload);
const { data: response } = yield call(postReportUser, payload);
yield put(reportUserComplete());
yield put(createFlashMessage(response));

View File

@ -26,7 +26,7 @@ import { createFlashMessage } from '../../components/Flash/redux';
function* submitNewAboutSaga({ payload }) {
try {
const response = yield call(putUpdateMyAbout, payload);
const { data: response } = yield call(putUpdateMyAbout, payload);
yield put(submitNewAboutComplete({ ...response, payload }));
yield put(createFlashMessage(response));
} catch (e) {
@ -36,7 +36,7 @@ function* submitNewAboutSaga({ payload }) {
function* submitNewUsernameSaga({ payload: username }) {
try {
const response = yield call(putUpdateMyUsername, username);
const { data: response } = yield call(putUpdateMyUsername, username);
yield put(submitNewUsernameComplete({ ...response, username }));
yield put(createFlashMessage(response));
} catch (e) {
@ -46,7 +46,7 @@ function* submitNewUsernameSaga({ payload: username }) {
function* submitProfileUISaga({ payload }) {
try {
const response = yield call(putUpdateMyProfileUI, payload);
const { data: response } = yield call(putUpdateMyProfileUI, payload);
yield put(submitProfileUIComplete({ ...response, payload }));
yield put(createFlashMessage(response));
} catch (e) {
@ -56,7 +56,7 @@ function* submitProfileUISaga({ payload }) {
function* updateUserFlagSaga({ payload: update }) {
try {
const response = yield call(putUpdateUserFlag, update);
const { data: response } = yield call(putUpdateUserFlag, update);
yield put(updateUserFlagComplete({ ...response, payload: update }));
yield put(createFlashMessage(response));
} catch (e) {
@ -67,7 +67,9 @@ function* updateUserFlagSaga({ payload: update }) {
function* validateUsernameSaga({ payload }) {
try {
yield delay(500);
const { exists } = yield call(getUsernameExists, payload);
const {
data: { exists }
} = yield call(getUsernameExists, payload);
yield put(validateUsernameComplete(exists));
} catch (e) {
yield put(validateUsernameError(e));
@ -76,10 +78,9 @@ function* validateUsernameSaga({ payload }) {
function* verifyCertificationSaga({ payload }) {
try {
const { response, isCertMap, completedChallenges } = yield call(
putVerifyCert,
payload
);
const {
data: { response, isCertMap, completedChallenges }
} = yield call(putVerifyCert, payload);
yield put(
verifyCertComplete({
...response,

View File

@ -13,7 +13,7 @@ function* updateMyEmailSaga({ payload: email = '' }) {
return;
}
try {
const response = yield call(putUserUpdateEmail, email);
const { data: response } = yield call(putUserUpdateEmail, email);
yield put(
updateMyEmailComplete({
...response,

View File

@ -7,7 +7,7 @@ import { showCertComplete, showCertError } from '.';
function* getShowCertSaga({ payload: { username, certSlug } }) {
try {
const response = yield call(getShowCert, username, certSlug);
const { data: response } = yield call(getShowCert, username, certSlug);
const { messages } = response;
if (messages && messages.length) {
for (let i = 0; i < messages.length; i++) {

View File

@ -1,52 +1,41 @@
import envData from '../../../config/env.json';
import axios from 'axios';
import Tokens from 'csrf';
import cookies from 'browser-cookies';
const { apiLocation, environment } = envData;
const { apiLocation } = envData;
const base = apiLocation;
const tokens = new Tokens();
// TODO: test on staging. Do we need 'include' everywhere?
const defaultOptions = {
credentials: environment === 'development' ? 'include' : 'same-site'
};
axios.defaults.withCredentials = true;
// _csrf is passed to the client as a cookie. Tokens are sent back to the server
// via headers:
function getCSRFToken() {
function setCSRFTokens() {
const _csrf = typeof window !== 'undefined' && cookies.get('_csrf');
if (!_csrf) {
return '';
} else {
return tokens.create(_csrf);
}
if (!_csrf) return;
axios.defaults.headers.post['CSRF-Token'] = tokens.create(_csrf);
axios.defaults.headers.put['CSRF-Token'] = tokens.create(_csrf);
}
function get(path) {
return fetch(`${base}${path}`, defaultOptions).then(res => res.json());
return axios.get(`${base}${path}`);
}
export function post(path, body) {
return request('POST', path, body);
setCSRFTokens();
return axios.post(`${base}${path}`, body);
}
function put(path, body) {
return request('PUT', path, body);
setCSRFTokens();
return axios.put(`${base}${path}`, body);
}
function request(method, path, body) {
const options = {
...defaultOptions,
method,
headers: {
'CSRF-Token': getCSRFToken(),
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
};
return fetch(`${base}${path}`, options).then(res => res.json());
}
// function del(path) {
// return axios.delete(`${base}${path}`);
// }
/** GET **/
@ -117,3 +106,5 @@ export function putUserUpdateEmail(email) {
export function putVerifyCert(certSlug) {
return put('/certificate/verify', { certSlug });
}
/** DELETE **/