-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (32 loc) · 1014 Bytes
/
index.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
function login(event) {
event.preventDefault();
var usernameElement = document.getElementById('username');
var username = usernameElement.value;
var passwordElement = document.getElementById('username');
var password = passwordElement.value;
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': 'http://localhost:5173',
'Access-Control-Allow-Methods': 'GET, POST, PUT',
'Access-Control-Allow-Headers': 'Content-Type'
},
body: JSON.stringify({
username: username,
password: password
})
};
//ToDo: Update the URL
fetch(
'https://sratrc-portal-backend-dev.onrender.com/api/v1/admin/auth/login',
options
)
.then((response) => response.json())
.then((data) => {
sessionStorage.setItem('token', data.token);
sessionStorage.setItem('roles', data.roles);
window.location.href = 'adminhome.html';
})
.catch((error) => console.error(error));
}