-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript.js
More file actions
51 lines (47 loc) · 1.29 KB
/
Script.js
File metadata and controls
51 lines (47 loc) · 1.29 KB
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
const form = document.getElementById("loginForm");
form.addEventListener("submit", async function (event) {
event.preventDefault();
const username = document.getElementById("username").value;
const password = document.getElementById("password").value;
const loginSuccessful = await fetchData(username, password);
if (loginSuccessful) {
alert("Invalid username or password");
} else {
alert("Login successful");
}
});
const fetchData = async (username, password) => {
const endpoint = "https://daring-bulldog-42.hasura.app/v1/graphql";
const headers = {
"content-type": "application/json",
"x-hasura-admin-secret":
"WBYT7CDij7UXKntv22DORjWL78G5felpV4qP0WQTojOaYuSABY68RcercW7DwwCo",
};
const data = fetch(endpoint, {
method: "POST",
headers: headers,
body: JSON.stringify({
query: `
query GetClients($username: String!, $password: String!) {
Clients(where: {Username: {_eq: $username}, Password: {_eq: $password}}) {
id
Username
Password
FirstName
LastName
MobileNumber
E_mail
Re_EnterPassword
}
}`,
variables: {
username: username,
password: password,
},
}),
})
.then((response) => response.json())
.then((e) => {
console.log(e.data.Clients[0]);
return e.data.Clients[0]});
};