-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsuccess.html
41 lines (32 loc) · 870 Bytes
/
success.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
<script>
const GITHUB_WORKER_URL = '';
const code = new URL(location.href).searchParams.get('code');
const error = new URL(location.href).searchParams.get('error');
if (code) {
// remove ?code=... from URL
const path = location.pathname + location.search.replace(/\bcode=\w+/, '').replace(/\?$/, '');
history.pushState({}, '', path);
login(code);
}
if (error) {
location.replace('/');
}
async function login(code) {
try {
const response = await fetch(GITHUB_WORKER_URL, {
method: 'POST',
mode: 'cors',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({ code }),
});
const result = await response.text();
if (result.error) {
alert(JSON.stringify(result, null, 2));
}
} catch (error) {
alert(error);
}
}
</script>