From b45ee480dbcb876579230e673b2835c7b1f830d6 Mon Sep 17 00:00:00 2001 From: 0hee0 Date: Tue, 31 Jan 2023 16:19:27 +0900 Subject: [PATCH] [#37] feat: implement auth api integration --- bowwowcare/src/services/auth.service.js | 46 ++++++++++++------------- bowwowcare/src/slices/auth.js | 10 +++--- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/bowwowcare/src/services/auth.service.js b/bowwowcare/src/services/auth.service.js index 1c9a14a..0c81e8d 100644 --- a/bowwowcare/src/services/auth.service.js +++ b/bowwowcare/src/services/auth.service.js @@ -1,33 +1,31 @@ import axios from "axios"; -const API_URL = "http://localhost:8080/users/"; +const API_URL = "http://localhost:8080/api/v1"; -const signup = (username, email, password) => { - return axios.post(API_URL + "signup", { - username, - email, - password, - }); +const signup = (data) => { + return axios({ + method: 'post', + url: `${API_URL}/sign/join`, + data: data + }) + .then(response => { + return response.data; + }) }; -const login = (email, password) => { - return axios - .post(API_URL + "login", { - email, - password, - }) - .then((response) => { - if (response.data.token) { - localStorage.setItem("user", JSON.stringify(response.data)); - } +const login = (data) => { + return axios({ + method: 'post', + url: `${API_URL}/sign/login`, + data: data + }) + .then(response => { + if (response.data.data.token) { + localStorage.setItem("user", JSON.stringify(response.data)); + } - return response.data; - }) - // .catch((error) => { - // if (error?.response?.data?.details) { - // return error.response.data.details - // } - // }) + return response.data; + }) }; const logout = () => { diff --git a/bowwowcare/src/slices/auth.js b/bowwowcare/src/slices/auth.js index fe88677..23f414f 100644 --- a/bowwowcare/src/slices/auth.js +++ b/bowwowcare/src/slices/auth.js @@ -7,9 +7,9 @@ const user = JSON.parse(localStorage.getItem("user")); export const signup = createAsyncThunk( "auth/signup", - async ({ username, email, password }, thunkAPI) => { + async (data, thunkAPI) => { try { - const response = await AuthService.signup(username, email, password); + const response = await AuthService.signup(data); thunkAPI.dispatch(setMessage(response.data.message)); return response.data; } catch (error) { @@ -27,10 +27,10 @@ export const signup = createAsyncThunk( export const login = createAsyncThunk( "auth/login", - async ({ email, password }, thunkAPI) => { + async (data, thunkAPI) => { try { - const data = await AuthService.login(email, password); - return { user: data }; + const userData = await AuthService.login(data); + return { user: userData }; } catch (error) { const message = (error.response &&