Replace fetch with Axios in client
Replace `.then` with await syntax where possible.
GitLab: #142
Change-Id: I6c132f49f152afa7e20919a1c70c539f2ad54878
diff --git a/client/src/pages/SetupLogin.tsx b/client/src/pages/SetupLogin.tsx
index 79079be..4608a59 100644
--- a/client/src/pages/SetupLogin.tsx
+++ b/client/src/pages/SetupLogin.tsx
@@ -17,6 +17,7 @@
*/
import GroupAddRounded from '@mui/icons-material/GroupAddRounded';
import { Box, Card, CardContent, Container, Fab, Input, Typography } from '@mui/material';
+import axios from 'axios';
import { HttpStatusCode } from 'jami-web-common';
import { FormEvent, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
@@ -38,17 +39,15 @@
}, []);
const adminCreation = async (password: string) => {
- const url = new URL('/setup/admin/create', apiUrl);
-
let response: Response;
try {
- response = await fetch(url, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({ password }),
- });
+ response = await axios.post(
+ '/setup/admin/create',
+ { password },
+ {
+ baseURL: apiUrl,
+ }
+ );
} catch (e) {
throw new Error(`Admin creation failed`);
}
@@ -59,18 +58,16 @@
};
const adminLogin = async (password: string) => {
- const url = new URL('/setup/admin/login', apiUrl);
-
let response: Response;
try {
- response = await fetch(url, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({ password }),
- });
- } catch (err) {
+ response = await axios.post(
+ '/setup/admin/login',
+ { password },
+ {
+ baseURL: apiUrl,
+ }
+ );
+ } catch (e) {
throw new Error(`Admin login failed`);
}