From 46bd31776081511b791100dd5726f5a63840dc2a Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Sat, 17 Aug 2024 13:03:24 -0700 Subject: [PATCH] Refactor register and login thunks --- Client/src/Features/Auth/authSlice.js | 4 ++-- Client/src/Utils/axiosConfig.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Client/src/Features/Auth/authSlice.js b/Client/src/Features/Auth/authSlice.js index 6da315fc4..e51d427ab 100644 --- a/Client/src/Features/Auth/authSlice.js +++ b/Client/src/Features/Auth/authSlice.js @@ -14,7 +14,7 @@ export const register = createAsyncThunk( "auth/register", async (form, thunkApi) => { try { - const res = await axiosInstance.post("/auth/register", form); + const res = await axiosInstance.registerUser(form); return res.data; } catch (error) { if (error.response.data) { @@ -31,7 +31,7 @@ export const register = createAsyncThunk( export const login = createAsyncThunk("auth/login", async (form, thunkApi) => { try { - const res = await axiosInstance.post(`/auth/login`, form); + const res = await axiosInstance.loginUser(form); return res.data; } catch (error) { if (error.response && error.response.data) { diff --git a/Client/src/Utils/axiosConfig.js b/Client/src/Utils/axiosConfig.js index 5cbfc9e06..518af41e1 100644 --- a/Client/src/Utils/axiosConfig.js +++ b/Client/src/Utils/axiosConfig.js @@ -90,4 +90,18 @@ axiosInstance.deleteMonitorById = async (authToken, monitorId) => { }); }; +// ********************************** +// Register a new user +// ********************************** +axiosInstance.registerUser = async (form) => { + return axiosInstance.post(`/auth/register`, form); +}; + +// ********************************** +// Log in an exisiting user +// ********************************** +axiosInstance.loginUser = async (form) => { + return axiosInstance.post(`/auth/login`, form); +}; + export default axiosInstance;