feat: testing
This commit is contained in:
parent
7a526f9983
commit
74f8ae6d84
|
@ -15,5 +15,6 @@
|
||||||
<h1>Please wait...</h1>
|
<h1>Please wait...</h1>
|
||||||
|
|
||||||
<script src="js/auth.js"></script>
|
<script src="js/auth.js"></script>
|
||||||
|
<script src="js/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -58,7 +58,9 @@
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<main class="pageContent" id="content">
|
<main class="pageContent" id="content">
|
||||||
CONTENT HERE
|
<script>
|
||||||
|
document.write(JSON.stringify(DiscordApi.getUser()));
|
||||||
|
</script>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer class="pageFooter container" id="footer">
|
<footer class="pageFooter container" id="footer">
|
||||||
|
|
11
js/auth.js
11
js/auth.js
|
@ -10,14 +10,7 @@ if(typeof authCode !== undefined) {
|
||||||
})
|
})
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(res => {
|
.then(res => {
|
||||||
fetch('https://discord.com/api/v10/users/@me', {
|
localStorage.setItem('token', res.access_token)
|
||||||
headers: {
|
localStorage.setItem('refresh', res.refresh_token)
|
||||||
'Authorization': `Bearer ${res.access_token}`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(res => res.json())
|
|
||||||
.then(res => {
|
|
||||||
console.log(res)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
33
js/main.js
33
js/main.js
|
@ -0,0 +1,33 @@
|
||||||
|
const DiscordApi = {
|
||||||
|
getUser: async () => {
|
||||||
|
if (typeof localStorage.getItem('token') === undefined)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
const req = await fetch('https://discord.com/api/v10/users/@me', {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${localStorage.getItem('token')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
DiscordApi.refreshToken();
|
||||||
|
|
||||||
|
return await req.json();
|
||||||
|
},
|
||||||
|
refreshToken: () => {
|
||||||
|
if (typeof localStorage.getItem('refresh') === undefined)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
fetch('https://crss-api.theclashfruit.workers.dev/refresh', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ authCode: localStorage.getItem('refresh') })
|
||||||
|
})
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(res => {
|
||||||
|
localStorage.setItem('token', res.access_token)
|
||||||
|
localStorage.setItem('refresh', res.refresh_token)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue