-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
68 lines (59 loc) · 1.58 KB
/
index.html
File metadata and controls
68 lines (59 loc) · 1.58 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Redirecting...</title>
<script>
let access = localStorage.getItem("access_token");
let refresh = localStorage.getItem("refresh_token");
async function validateAccess() {
if (!access || access.length < 10) {
return false;
}
try {
const res = await fetch("https://admin-backend.pwindows.qzz.io/protected", {
headers: { Authorization: `Bearer ${access}` },
});
return res.ok;
} catch {
return false;
}
}
async function refreshAccess() {
if (!refresh || refresh.length < 10) {
return false;
}
try {
const res = await fetch("https://admin-backend.pwindows.qzz.io/token/refresh", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ refresh_token: refresh }),
});
if (!res.ok) return false;
const data = await res.json();
localStorage.setItem("access_token", data.access_token);
return true;
} catch {
return false;
}
}
async function redirectFlow() {
const valid = await validateAccess();
if (valid) {
window.location.href = "success.html";
return;
}
const refreshed = await refreshAccess();
if (refreshed) {
window.location.href = "success.html";
} else {
window.location.href = "login.html";
}
}
redirectFlow();
</script>
</head>
<body>
<p>Redirecting...</p>
</body>
</html>