Resolved conflict
This commit is contained in:
commit
ff2e08b483
8 files changed
+54
-40
No files matched your search
@@ -1,7 +1,6 @@
|
|||||||
import axios from "axios";
|
import axiosInstance from "../../Utils/axiosConfig";
|
||||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
||||||
import { jwtDecode } from "jwt-decode";
|
import { jwtDecode } from "jwt-decode";
|
||||||
const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
|
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@@ -15,7 +14,7 @@ export const register = createAsyncThunk(
|
|||||||
"auth/register",
|
"auth/register",
|
||||||
async (form, thunkApi) => {
|
async (form, thunkApi) => {
|
||||||
try {
|
try {
|
||||||
const res = await axios.post(`${BASE_URL}/auth/register`, form);
|
const res = await axiosInstance.post("/auth/register", form);
|
||||||
return res.data;
|
return res.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response.data) {
|
if (error.response.data) {
|
||||||
@@ -28,7 +27,7 @@ export const register = createAsyncThunk(
|
|||||||
|
|
||||||
export const login = createAsyncThunk("auth/login", async (form, thunkApi) => {
|
export const login = createAsyncThunk("auth/login", async (form, thunkApi) => {
|
||||||
try {
|
try {
|
||||||
const res = await axios.post(`${BASE_URL}/auth/login`, form);
|
const res = await axiosInstance.post(`/auth/login`, form);
|
||||||
return res.data;
|
return res.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response && error.response.data) {
|
if (error.response && error.response.data) {
|
||||||
@@ -51,7 +50,7 @@ export const update = createAsyncThunk(
|
|||||||
fd.append("firstname", form.firstname);
|
fd.append("firstname", form.firstname);
|
||||||
fd.append("lastname", form.lastname);
|
fd.append("lastname", form.lastname);
|
||||||
if (form.file && form.file !== "") {
|
if (form.file && form.file !== "") {
|
||||||
const imageResult = await axios.get(form.file, {
|
const imageResult = await axiosInstance.get(form.file, {
|
||||||
responseType: "blob",
|
responseType: "blob",
|
||||||
});
|
});
|
||||||
fd.append("profileImage", imageResult.data);
|
fd.append("profileImage", imageResult.data);
|
||||||
@@ -59,7 +58,7 @@ export const update = createAsyncThunk(
|
|||||||
form.deleteProfileImage &&
|
form.deleteProfileImage &&
|
||||||
fd.append("deleteProfileImage", form.deleteProfileImage);
|
fd.append("deleteProfileImage", form.deleteProfileImage);
|
||||||
|
|
||||||
const res = await axios.post(`${BASE_URL}/auth/user/${user._id}`, fd, {
|
const res = await axiosInstance.post(`/auth/user/${user._id}`, fd, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
"Content-Type": "multipart/form-data",
|
"Content-Type": "multipart/form-data",
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import axios from "axios";
|
|
||||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
||||||
import { jwtDecode } from "jwt-decode";
|
import { jwtDecode } from "jwt-decode";
|
||||||
const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
|
import axiosInstance from "../../Utils/axiosConfig";
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
monitors: [],
|
monitors: [],
|
||||||
@@ -16,7 +14,7 @@ export const createMonitor = createAsyncThunk(
|
|||||||
try {
|
try {
|
||||||
const { authToken, monitor } = data;
|
const { authToken, monitor } = data;
|
||||||
|
|
||||||
const res = await axios.post(`${BASE_URL}/monitors`, monitor, {
|
const res = await axiosInstance.post(`/monitors`, monitor, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${authToken}`,
|
Authorization: `Bearer ${authToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -36,9 +34,7 @@ export const getMonitors = createAsyncThunk(
|
|||||||
"monitors/getMonitors",
|
"monitors/getMonitors",
|
||||||
async (token, thunkApi) => {
|
async (token, thunkApi) => {
|
||||||
try {
|
try {
|
||||||
const res = await axios.get(
|
const res = await axiosInstance.get("/monitors");
|
||||||
import.meta.env.VITE_APP_API_BASE_URL + "/monitors"
|
|
||||||
);
|
|
||||||
return res.data;
|
return res.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response && error.response.data) {
|
if (error.response && error.response.data) {
|
||||||
@@ -54,14 +50,11 @@ export const getMonitorsByUserId = createAsyncThunk(
|
|||||||
async (token, thunkApi) => {
|
async (token, thunkApi) => {
|
||||||
const user = jwtDecode(token);
|
const user = jwtDecode(token);
|
||||||
try {
|
try {
|
||||||
const res = await axios.get(
|
const res = await axiosInstance.get("/monitors/user/" + user._id, {
|
||||||
import.meta.env.VITE_APP_API_BASE_URL + "/monitors/user/" + user._id,
|
headers: {
|
||||||
{
|
Authorization: `Bearer ${token}`,
|
||||||
headers: {
|
},
|
||||||
Authorization: `Bearer ${token}`,
|
});
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return res.data;
|
return res.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response && error.response.data) {
|
if (error.response && error.response.data) {
|
||||||
|
|||||||
@@ -7,11 +7,9 @@ import Button from "../../Components/Button";
|
|||||||
import LeftArrow from "../../assets/Images/arrow-left.png";
|
import LeftArrow from "../../assets/Images/arrow-left.png";
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { recoveryValidation } from "../../Validation/validation";
|
import { recoveryValidation } from "../../Validation/validation";
|
||||||
import axios from "axios";
|
import axiosInstance from "../../Utils/axiosConfig";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
|
|
||||||
|
|
||||||
const ForgotPassword = () => {
|
const ForgotPassword = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
@@ -50,7 +48,7 @@ const ForgotPassword = () => {
|
|||||||
if (error !== undefined) {
|
if (error !== undefined) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
await axios.post(`${BASE_URL}/auth/recovery/request`, form);
|
await axiosInstance.post(`/auth/recovery/request`, form);
|
||||||
navigate("/check-email");
|
navigate("/check-email");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
//TODO display error (Toast?)
|
//TODO display error (Toast?)
|
||||||
|
|||||||
@@ -9,12 +9,10 @@ import CheckBox from "../../Components/Checkbox/Checkbox";
|
|||||||
import Button from "../../Components/Button";
|
import Button from "../../Components/Button";
|
||||||
import Google from "../../assets/Images/Google.png";
|
import Google from "../../assets/Images/Google.png";
|
||||||
import PasswordTextField from "../../Components/TextFields/Password/PasswordTextField";
|
import PasswordTextField from "../../Components/TextFields/Password/PasswordTextField";
|
||||||
|
import axiosInstance from "../../Utils/axiosConfig";
|
||||||
import { loginValidation } from "../../Validation/validation";
|
import { loginValidation } from "../../Validation/validation";
|
||||||
import { login } from "../../Features/Auth/authSlice";
|
import { login } from "../../Features/Auth/authSlice";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import axios from "axios";
|
|
||||||
const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
|
|
||||||
|
|
||||||
const Login = () => {
|
const Login = () => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -33,8 +31,8 @@ const Login = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
axios
|
axiosInstance
|
||||||
.get(BASE_URL + "/auth/users/admin")
|
.get("/auth/users/admin")
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.data.data === false) {
|
if (response.data.data === false) {
|
||||||
navigate("/register");
|
navigate("/register");
|
||||||
|
|||||||
@@ -11,12 +11,9 @@ import Check from "../../Components/Check/Check";
|
|||||||
import Button from "../../Components/Button";
|
import Button from "../../Components/Button";
|
||||||
import Google from "../../assets/Images/Google.png";
|
import Google from "../../assets/Images/Google.png";
|
||||||
import { registerValidation } from "../../Validation/validation";
|
import { registerValidation } from "../../Validation/validation";
|
||||||
|
import axiosInstance from "../../Utils/axiosConfig";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { register } from "../../Features/Auth/authSlice";
|
import { register } from "../../Features/Auth/authSlice";
|
||||||
import axios from "axios";
|
|
||||||
|
|
||||||
const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
|
|
||||||
|
|
||||||
const Register = () => {
|
const Register = () => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -41,8 +38,8 @@ const Register = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
axios
|
axiosInstance
|
||||||
.get(BASE_URL + "/auth/users/admin")
|
.get("/auth/users/admin")
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.data.data === true) {
|
if (response.data.data === true) {
|
||||||
navigate("/login");
|
navigate("/login");
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ import LeftArrow from "../../assets/Images/arrow-left.png";
|
|||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { newPasswordValidation } from "../../Validation/validation";
|
import { newPasswordValidation } from "../../Validation/validation";
|
||||||
import axios from "axios";
|
import axiosInstance from "../../Utils/axiosConfig";
|
||||||
const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
|
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
const SetNewPassword = () => {
|
const SetNewPassword = () => {
|
||||||
@@ -33,10 +32,10 @@ const SetNewPassword = () => {
|
|||||||
// TODO show loading spinner
|
// TODO show loading spinner
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
await axios.post(`${BASE_URL}/auth/recovery/validate`, {
|
await axiosInstance.post("/auth/recovery/validate", {
|
||||||
recoveryToken: token,
|
recoveryToken: token,
|
||||||
});
|
});
|
||||||
await axios.post(`${BASE_URL}/auth/recovery/reset`, {
|
await axiosInstance.post("/auth/recovery/reset", {
|
||||||
...form,
|
...form,
|
||||||
recoveryToken: token,
|
recoveryToken: token,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
import { clearAuthState } from "../Features/Auth/authSlice";
|
||||||
|
const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
|
||||||
|
|
||||||
|
let store;
|
||||||
|
|
||||||
|
export const injectStore = (s) => {
|
||||||
|
store = s;
|
||||||
|
};
|
||||||
|
|
||||||
|
const axiosInstance = axios.create({
|
||||||
|
baseURL: BASE_URL,
|
||||||
|
});
|
||||||
|
|
||||||
|
axiosInstance.interceptors.response.use(
|
||||||
|
(response) => response,
|
||||||
|
(error) => {
|
||||||
|
console.error(error);
|
||||||
|
if (error.response && error.response.status === 401) {
|
||||||
|
console.log("Invalid token revoked");
|
||||||
|
store.dispatch(clearAuthState());
|
||||||
|
}
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export default axiosInstance;
|
||||||
@@ -8,6 +8,9 @@ import { ThemeProvider } from "@mui/material";
|
|||||||
import { Provider } from "react-redux";
|
import { Provider } from "react-redux";
|
||||||
import { persistor, store } from "./store";
|
import { persistor, store } from "./store";
|
||||||
import { PersistGate } from "redux-persist/integration/react";
|
import { PersistGate } from "redux-persist/integration/react";
|
||||||
|
import { injectStore } from "./Utils/axiosConfig.js";
|
||||||
|
|
||||||
|
injectStore(store);
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById("root")).render(
|
ReactDOM.createRoot(document.getElementById("root")).render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
|
|||||||
Reference in new issue
Block a user