-
Notifications
You must be signed in to change notification settings - Fork 0
/
signin.html
100 lines (85 loc) · 2.42 KB
/
signin.html
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="stylesheet" href="./style/nav.css" />
<link rel="stylesheet" href="/style/signup.css">
<script
src="https://kit.fontawesome.com/683b4b40e3.js"
crossorigin="anonymous"
></script>
</head>
<body>
<div id="con">
<div id="nav"></div>
<div id="body">
<form action="" id="fom">
<h2>Sign-In</h2>
<input
type="text"
id="username"
placeholder="Enter Your User name"
/><br />
<input type="password" id="password" placeholder="Enter your Password" /><br />
<input type="submit" />
</form>
</div>
</div>
</body>
</html>
<script type="module">
import navbar from "./components/navbar.js";
let navone = document.getElementById("nav");
navone.innerHTML = navbar();
document.getElementById("fom").addEventListener("submit", myfnc);
let data;
async function myfnc(e) {
e.preventDefault();
try {
data = {
username: document.getElementById("username").value,
password: document.getElementById("password").value
};
} catch (er) {
console.log("er:", er);
}
console.log(data)
data = JSON.stringify(data);
let api = ` https://masai-api-mocker.herokuapp.com/auth/login`
let response = await fetch(api, {
method: "POST",
body: data,
headers: {
"Content-Type": "application/json",
},
});
let res = await response.json();
console.log('res:', res)
if(res.error == false){
setTimeout(() => {
alert("sign-in successful")
window.location.href="home.html"
}, 2000);
}
let username = document.getElementById("username").value
getuser(username,res.token)
console.log('res:', res.token)
}
async function getuser(username,token){
let api = ` https://masai-api-mocker.herokuapp.com/user/${username}`
let res = await fetch(api,{
headers:{
"Content-Type" : "application/json",
"Authorization" : `Bearer ${token}`
}
})
let data = await res.json()
share(data)
}
function share(data){
localStorage.setItem("details",JSON.stringify(data))
}
</script>