-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathscript.js
43 lines (31 loc) · 1.26 KB
/
script.js
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
document.getElementById('frm-register').addEventListener('submit', async function(e) {
e.preventDefault();
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
//send the request to the server
const response = await fetch('/auth/register', {
method: 'POST',
headers: {
'Content-Type' : 'application/json'
},
body: JSON.stringify({ name, email, password })
});
const data = await response.json();
alert(data.message);
});
document.getElementById('frm-login').addEventListener('submit', async function(e) {
e.preventDefault();
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
//send the request to the server
const response = await fetch('/auth/login', {
method: 'POST',
headers: {
'Content-Type' : 'application/json'
},
body: JSON.stringify({ email, password })
});
const data = await response.json();
alert(data.message + 'Welcome ' + data.name + ' of email address: ' + data.email);
});