Redirect
This commit is contained in:
parent
5c617fd293
commit
02a50719b0
@ -19,8 +19,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function redirectLogin() {
|
export function redirectLogin() {
|
||||||
// TODO: 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=`
|
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() {
|
export function clearLocalStorage() {
|
||||||
|
@ -3,6 +3,10 @@
|
|||||||
import {redirectLogin, setToken} from '../includes/Auth.svelte'
|
import {redirectLogin, setToken} from '../includes/Auth.svelte'
|
||||||
import {API_URL} from "../js/constants";
|
import {API_URL} from "../js/constants";
|
||||||
import {errorPage} from '../js/util'
|
import {errorPage} from '../js/util'
|
||||||
|
import {navigateTo} from "svelte-router-spa";
|
||||||
|
|
||||||
|
export let currentRoute;
|
||||||
|
let state = currentRoute.queryParams.state;
|
||||||
|
|
||||||
async function process() {
|
async function process() {
|
||||||
const code = new URLSearchParams(window.location.search).get('code')
|
const code = new URLSearchParams(window.location.search).get('code')
|
||||||
@ -18,15 +22,30 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
setToken(res.data.token)
|
setToken(res.data.token);
|
||||||
window.location.href = '/'
|
|
||||||
|
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()
|
process()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
background-color: #121212;
|
background-color: #121212;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
Loading…
x
Reference in New Issue
Block a user