pages/js/auth.js
2023-08-24 16:48:26 +02:00

18 lines
503 B
JavaScript

const authCode = new URL(document.location).searchParams.get('code')
if(typeof authCode !== undefined) {
fetch('https://crss-api.theclashfruit.workers.dev/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ authCode: authCode })
})
.then(res => res.json())
.then(res => {
localStorage.setItem('token', res.access_token)
localStorage.setItem('refresh', res.refresh_token)
document.location = "/"
})
}