Added configured axios instance with 401 interceptor, refactored all requests to use axios instance
This commit is contained in:
1 parent
fb292d23a6
commit
10c8751c6b
8 files changed
+56
-40
No files matched your search
@@ -7,11 +7,9 @@ import Button from "../../Components/Button";
|
||||
import LeftArrow from "../../assets/Images/arrow-left.png";
|
||||
import { useState, useEffect } from "react";
|
||||
import { recoveryValidation } from "../../Validation/validation";
|
||||
import axios from "axios";
|
||||
import axiosInstance from "../../Utils/axiosConfig";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
|
||||
|
||||
const ForgotPassword = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
@@ -50,7 +48,7 @@ const ForgotPassword = () => {
|
||||
if (error !== undefined) {
|
||||
throw error;
|
||||
}
|
||||
await axios.post(`${BASE_URL}/auth/recovery/request`, form);
|
||||
await axiosInstance.post(`/auth/recovery/request`, form);
|
||||
navigate("/check-email");
|
||||
} catch (error) {
|
||||
//TODO display error (Toast?)
|
||||
|
||||
@@ -9,12 +9,10 @@ import CheckBox from "../../Components/Checkbox/Checkbox";
|
||||
import Button from "../../Components/Button";
|
||||
import Google from "../../assets/Images/Google.png";
|
||||
import PasswordTextField from "../../Components/TextFields/Password/PasswordTextField";
|
||||
|
||||
import axiosInstance from "../../Utils/axiosConfig";
|
||||
import { loginValidation } from "../../Validation/validation";
|
||||
import { login } from "../../Features/Auth/authSlice";
|
||||
import { useDispatch } from "react-redux";
|
||||
import axios from "axios";
|
||||
const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
|
||||
|
||||
const Login = () => {
|
||||
const dispatch = useDispatch();
|
||||
@@ -33,8 +31,8 @@ const Login = () => {
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
axios
|
||||
.get(BASE_URL + "/auth/users/admin")
|
||||
axiosInstance
|
||||
.get("/auth/users/admin")
|
||||
.then((response) => {
|
||||
if (response.data.data === false) {
|
||||
navigate("/register");
|
||||
|
||||
@@ -11,12 +11,9 @@ import Check from "../../Components/Check/Check";
|
||||
import Button from "../../Components/Button";
|
||||
import Google from "../../assets/Images/Google.png";
|
||||
import { registerValidation } from "../../Validation/validation";
|
||||
|
||||
import axiosInstance from "../../Utils/axiosConfig";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { register } from "../../Features/Auth/authSlice";
|
||||
import axios from "axios";
|
||||
|
||||
const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
|
||||
|
||||
const Register = () => {
|
||||
const dispatch = useDispatch();
|
||||
@@ -41,8 +38,8 @@ const Register = () => {
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
axios
|
||||
.get(BASE_URL + "/auth/users/admin")
|
||||
axiosInstance
|
||||
.get("/auth/users/admin")
|
||||
.then((response) => {
|
||||
if (response.data.data === true) {
|
||||
navigate("/login");
|
||||
|
||||
@@ -8,8 +8,7 @@ import LeftArrow from "../../assets/Images/arrow-left.png";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useState, useEffect } from "react";
|
||||
import { newPasswordValidation } from "../../Validation/validation";
|
||||
import axios from "axios";
|
||||
const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
|
||||
import axiosInstance from "../../Utils/axiosConfig";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
const SetNewPassword = () => {
|
||||
@@ -33,10 +32,10 @@ const SetNewPassword = () => {
|
||||
// TODO show loading spinner
|
||||
setIsLoading(true);
|
||||
try {
|
||||
await axios.post(`${BASE_URL}/auth/recovery/validate`, {
|
||||
await axiosInstance.post("/auth/recovery/validate", {
|
||||
recoveryToken: token,
|
||||
});
|
||||
await axios.post(`${BASE_URL}/auth/recovery/reset`, {
|
||||
await axiosInstance.post("/auth/recovery/reset", {
|
||||
...form,
|
||||
recoveryToken: token,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user