auth.js
971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const axios = require("axios").default;
const handleSignup = async ({ username, country, email, password }) => {
try {
const response = await axios.post("http://localhost:8080/api/users", {
username,
country,
email,
password,
});
if (response.data) {
console.log("signup request sent...");
localStorage.setItem("user-token", JSON.stringify(response.data));
return "success";
}
} catch (err) {
console.log(err);
}
};
const handleLogin = async ({ email, password }) => {
try {
const response = await axios.post("http://localhost:8080/api/users/login", {
email,
password,
});
if (response.data) {
console.log("signin request sent...");
localStorage.setItem("user-token", JSON.stringify(response.data));
return "success";
}
} catch (err) {
console.log(err);
}
};
const authService = {
handleSignup,
handleLogin,
};
export default authService;