Redirect
This commit is contained in:
parent
5c617fd293
commit
02a50719b0
@ -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() {
|
||||
|
@ -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,15 +22,30 @@
|
||||
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()
|
||||
</script>
|
||||
|
||||
<style>
|
||||
body {
|
||||
background-color: #121212;
|
||||
}
|
||||
body {
|
||||
background-color: #121212;
|
||||
}
|
||||
</style>
|
Loading…
x
Reference in New Issue
Block a user