Skip to content

Commit

Permalink
feat: upgrade axios for client
Browse files Browse the repository at this point in the history
  • Loading branch information
ImenOuidou authored and gary-van-woerkens committed Mar 27, 2024
1 parent e5d2880 commit f7466d7
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 12 additions & 6 deletions src/client/src/containers/UsersFeedback/UsersFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand Down
40 changes: 29 additions & 11 deletions src/client/src/services/Auth/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
7 changes: 2 additions & 5 deletions src/client/src/services/Http/Http.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import axios from "axios";
import buildURL from "axios/lib/helpers/buildURL";

import Auth from "../Auth";
import Config from "../Config";
Expand All @@ -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;
};

Expand All @@ -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;
},
Expand All @@ -46,6 +45,4 @@ Http.interceptors.response.use(
}
);

Http.buildURL = buildURL;

export default Http;
45 changes: 26 additions & 19 deletions src/client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit f7466d7

Please sign in to comment.