This commit is contained in:
rxdn 2022-07-16 18:54:43 +01:00
parent 5c617fd293
commit 02a50719b0
2 changed files with 26 additions and 7 deletions

View File

@ -19,8 +19,8 @@
}
export function redirectLogin() {
// TODO: State
window.location.href = `https://discordapp.com/oauth2/authorize?response_type=code&redirect_uri=${OAUTH.redirectUri}&scope=identify%20guilds&client_id=${OAUTH.clientId}&state=`
let state = btoa(new URL(window.location.href).pathname);
window.location.href = `https://discordapp.com/oauth2/authorize?response_type=code&redirect_uri=${OAUTH.redirectUri}&scope=identify%20guilds&client_id=${OAUTH.clientId}&state=${state}`;
}
export function clearLocalStorage() {

View File

@ -3,6 +3,10 @@
import {redirectLogin, setToken} from '../includes/Auth.svelte'
import {API_URL} from "../js/constants";
import {errorPage} from '../js/util'
import {navigateTo} from "svelte-router-spa";
export let currentRoute;
let state = currentRoute.queryParams.state;
async function process() {
const code = new URLSearchParams(window.location.search).get('code')
@ -18,8 +22,23 @@
return
}
setToken(res.data.token)
window.location.href = '/'
setToken(res.data.token);
let path = '/';
try {
if (state !== undefined && state.length > 0) {
path = atob(state);
if (path === '/callback') {
path = '/';
}
}
} catch (e) {
console.log(`Error parsing state: ${e}`)
} finally {
navigateTo(path);
}
}
process()