From f7466d70af41e4a42e6aeaec960ede7cf5142dff Mon Sep 17 00:00:00 2001 From: Imen Chermiti Date: Tue, 26 Mar 2024 14:29:22 +0100 Subject: [PATCH] feat: upgrade axios for client --- src/client/package.json | 2 +- .../containers/UsersFeedback/UsersFeedback.js | 18 +++++--- src/client/src/services/Auth/Auth.js | 40 ++++++++++++----- src/client/src/services/Http/Http.js | 7 +-- src/client/yarn.lock | 45 +++++++++++-------- 5 files changed, 70 insertions(+), 42 deletions(-) diff --git a/src/client/package.json b/src/client/package.json index b03d81788..f0b54cc6c 100644 --- a/src/client/package.json +++ b/src/client/package.json @@ -13,7 +13,7 @@ "@sentry/browser": "^5.14.2", "@socialgouv/codes-naf": "^1.1.0", "OhMyCache": "^1.1.1", - "axios": "^0.19.2", + "axios": "^1.6.8", "bulma": "^0.9.0", "bulma-extensions": "^6.2.7", "chart.js": "^4.3.0", diff --git a/src/client/src/containers/UsersFeedback/UsersFeedback.js b/src/client/src/containers/UsersFeedback/UsersFeedback.js index 62729a74d..a386d79ba 100644 --- a/src/client/src/containers/UsersFeedback/UsersFeedback.js +++ b/src/client/src/containers/UsersFeedback/UsersFeedback.js @@ -33,13 +33,19 @@ const UsersFeedback = ({ const sendFeedback = (e) => { e.preventDefault(); - Http.post("/feedback", { - params: { - comment: state.comment, - rate: state.rate, - useful: state.useful === "thumbup", + Http.post( + "/feedback", + { + params: { + comment: state.comment, + rate: state.rate, + useful: state.useful === "thumbup", + }, }, - }) + { + headers: { "Content-Type": "application/json" }, + } + ) .catch((e) => { handleError(e); }) diff --git a/src/client/src/services/Auth/Auth.js b/src/client/src/services/Auth/Auth.js index 843917678..2c6fc7923 100644 --- a/src/client/src/services/Auth/Auth.js +++ b/src/client/src/services/Auth/Auth.js @@ -7,17 +7,29 @@ const AUTH_USER_ID = "user_id"; export default class Auth { static sendCode(email) { - return Http.post("/requestAuthCode", { - email, - }); + return Http.post( + "/requestAuthCode", + { + email, + }, + { + headers: { "Content-Type": "application/json" }, + } + ); } static login(email, code, isCheckedSubscription) { - return Http.post("/login", { - code, - email, - isCheckedSubscription, - }).then((response) => { + return Http.post( + "/login", + { + code, + email, + isCheckedSubscription, + }, + { + headers: { "Content-Type": "application/json" }, + } + ).then((response) => { if (response.data && response.data.success) { Local.set(AUTH_KEY, response.data.token); Local.set(AUTH_USER_ID, response.data.saltedEmail); @@ -33,9 +45,15 @@ export default class Auth { } static tempLogin(credential) { - return Http.post("/tempLogin", { - credential, - }).then((response) => { + return Http.post( + "/tempLogin", + { + credential, + }, + { + headers: { "Content-Type": "application/json" }, + } + ).then((response) => { if (response.data && response.data.success) { Local.set(AUTH_KEY, response.data.token); Local.set(AUTH_USER_ID, response.data.saltedEmail); diff --git a/src/client/src/services/Http/Http.js b/src/client/src/services/Http/Http.js index 772b52b79..092fda184 100644 --- a/src/client/src/services/Http/Http.js +++ b/src/client/src/services/Http/Http.js @@ -1,5 +1,4 @@ import axios from "axios"; -import buildURL from "axios/lib/helpers/buildURL"; import Auth from "../Auth"; import Config from "../Config"; @@ -12,7 +11,7 @@ Http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded"; Http.setAuthorization = (token) => { - Http.defaults.headers.common["Authorization"] = token; + Http.defaults.headers["Authorization"] = token; return Http; }; @@ -25,7 +24,7 @@ Http.formData = (data) => { Http.interceptors.request.use( (config) => { if (Auth.isLogged()) { - config.headers.common["Authorization"] = `Bearer ${Auth.getToken()}`; + config.headers["Authorization"] = `Bearer ${Auth.getToken()}`; } return config; }, @@ -46,6 +45,4 @@ Http.interceptors.response.use( } ); -Http.buildURL = buildURL; - export default Http; diff --git a/src/client/yarn.lock b/src/client/yarn.lock index b82ae0e91..e1e9c0124 100644 --- a/src/client/yarn.lock +++ b/src/client/yarn.lock @@ -3007,12 +3007,14 @@ axe-core@^4.3.5: resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.4.1.tgz#7dbdc25989298f9ad006645cd396782443757413" integrity sha512-gd1kmb21kwNuWr6BQz8fv6GNECPBnUasepcoLbekws23NVBLODdsClRZ+bQ8+9Uomf3Sm3+Vwn0oYG9NvwnJCw== -axios@^0.19.2: - version "0.19.2" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27" - integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA== +axios@^1.6.8: + version "1.6.8" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66" + integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ== dependencies: - follow-redirects "1.5.10" + follow-redirects "^1.15.6" + form-data "^4.0.0" + proxy-from-env "^1.1.0" axobject-query@^2.2.0: version "2.2.0" @@ -4143,13 +4145,6 @@ debug@4, debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.2: dependencies: ms "2.1.2" -debug@=3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" - integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g== - dependencies: - ms "2.0.0" - debug@^3.1.1, debug@^3.2.7: version "3.2.7" resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.7.tgz#72580b7e9145fb39b6676f9c5e5fb100b934179a" @@ -5258,18 +5253,16 @@ flatted@^3.1.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.5.tgz#76c8584f4fc843db64702a6bd04ab7a8bd666da3" integrity sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg== -follow-redirects@1.5.10: - version "1.5.10" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a" - integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ== - dependencies: - debug "=3.1.0" - follow-redirects@^1.0.0: version "1.14.9" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7" integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w== +follow-redirects@^1.15.6: + version "1.15.6" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" + integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== + fork-ts-checker-webpack-plugin@^6.5.0: version "6.5.0" resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-6.5.0.tgz#0282b335fa495a97e167f69018f566ea7d2a2b5e" @@ -5298,6 +5291,15 @@ form-data@^3.0.0: combined-stream "^1.0.8" mime-types "^2.1.12" +form-data@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" + integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + forwarded@0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.2.0.tgz#2269936428aad4c15c7ebe9779a84bf0b2a81811" @@ -8773,6 +8775,11 @@ proxy-addr@~2.0.7: forwarded "0.2.0" ipaddr.js "1.9.1" +proxy-from-env@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" + integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== + psl@^1.1.33: version "1.8.0" resolved "https://registry.yarnpkg.com/psl/-/psl-1.8.0.tgz#9326f8bcfb013adcc005fdff056acce020e51c24"