forked from bryantson/OpensourceDotComDemos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
54 lines (50 loc) · 1.57 KB
/
index.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Static Web Apps - Authentication</title>
</head>
<body>
<h1>Qapitol QA Sauron - Documentation</h1>
<div id="loginButtons"></div>
<div id="userInfo">
</div>
<code id="userDetails">
</code>
<div id="apiResult">
</div>
<p id="data"></p>
<script>
const providers = ["aad"];
const loginButtons = document.getElementById("loginButtons");
providers.forEach(provider => {
const button = document.createElement("button");
button.innerText = 'Login with Microsoft';
button.onclick = () => {
window.location.href = `/.auth/login/${provider}`;
};
loginButtons.appendChild(button);
});
myFun().then(data => {
if (data.clientPrincipal) {
var pattern = /@gmail.com/;
var result = pattern.test(`${data.clientPrincipal.userDetails}`);
if (result){
console.log("You are authorized");
window.location.href = '/main.html';
}
else{
console.log("You are not authorized");
window.location.href = '/index.html';
}
}
});
async function myFun() {
const response = await fetch('/.auth/me');
const data = await response.json();
return data;
}
</script>
</body>
</html>