Skip to content

Commit

Permalink
Merge pull request #44 from 2022-2-Graduation-Project/feature/37-logi…
Browse files Browse the repository at this point in the history
…n-signup

[#37] feat: implement auth api integration
  • Loading branch information
suzinxix authored Jan 31, 2023
2 parents a644841 + b45ee48 commit c263628
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
46 changes: 22 additions & 24 deletions bowwowcare/src/services/auth.service.js
Original file line number Diff line number Diff line change
@@ -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 = () => {
Expand Down
10 changes: 5 additions & 5 deletions bowwowcare/src/slices/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 &&
Expand Down

0 comments on commit c263628

Please sign in to comment.