Refactor register and login thunks
This commit is contained in:
1 parent
41f975cdfa
commit
46bd317760
2 files changed
+16
-2
No files matched your search
@@ -14,7 +14,7 @@ export const register = createAsyncThunk(
|
|||||||
"auth/register",
|
"auth/register",
|
||||||
async (form, thunkApi) => {
|
async (form, thunkApi) => {
|
||||||
try {
|
try {
|
||||||
const res = await axiosInstance.post("/auth/register", form);
|
const res = await axiosInstance.registerUser(form);
|
||||||
return res.data;
|
return res.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response.data) {
|
if (error.response.data) {
|
||||||
@@ -31,7 +31,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 axiosInstance.post(`/auth/login`, form);
|
const res = await axiosInstance.loginUser(form);
|
||||||
return res.data;
|
return res.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response && error.response.data) {
|
if (error.response && error.response.data) {
|
||||||
|
|||||||
@@ -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;
|
export default axiosInstance;
|
||||||
Reference in new issue
Block a user