-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogin.js
More file actions
32 lines (27 loc) · 905 Bytes
/
login.js
File metadata and controls
32 lines (27 loc) · 905 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
const email = document.querySelector("#email");
const password = document.querySelector("#password");
const login = document.querySelector("#button");
login.addEventListener("click", Login);
function Login() {
if(!email.value) return alert("Please input id.");
if(!password.value) return alert("Please input password.");
const req = {
email : email.value,
password : password.value,
}
fetch("/user/login", {
method: "POST",
headers:{
"Content-Type": "application/json",
},
body: JSON.stringify(req)
})
.then((res) => res.json())
.then((res) => {
if(res.code === 200) {
localStorage.setItem('access_token', res.data.access_token);
localStorage.setItem('refresh_token', res.data.refresh_token);
location.href = "/";
} else return alert(res.message);
})
}