forked from blisstown/campfire
i think i finally fixed the state management awfulness
This commit is contained in:
parent
6953b49563
commit
40be540527
18 changed files with 402 additions and 417 deletions
|
@ -1,20 +1,5 @@
|
|||
import { Client } from '$lib/client/client.js';
|
||||
import { goto } from '$app/navigation';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
export const ssr = false;
|
||||
|
||||
export async function load({ params, url }) {
|
||||
const client = get(Client.get());
|
||||
let auth_code = url.searchParams.get("code");
|
||||
if (auth_code) {
|
||||
client.getToken(auth_code).then(() => {
|
||||
client.save();
|
||||
goto("/");
|
||||
});
|
||||
}
|
||||
error(400, {
|
||||
message: "Bad request"
|
||||
});
|
||||
export async function load({ url }) {
|
||||
return {
|
||||
code: url.searchParams.get("code") || false
|
||||
};
|
||||
}
|
||||
|
|
35
src/routes/callback/+page.svelte
Normal file
35
src/routes/callback/+page.svelte
Normal file
|
@ -0,0 +1,35 @@
|
|||
<script>
|
||||
import { client } from '$lib/client/client.js';
|
||||
import { goto } from '$app/navigation';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
export let data;
|
||||
|
||||
let auth_code = data.code;
|
||||
|
||||
if (!auth_code) {
|
||||
error(400, { message: "Bad request" });
|
||||
} else {
|
||||
get(client).getToken(auth_code).then(token => {
|
||||
if (!token) {
|
||||
error(400, { message: "Invalid auth code provided" });
|
||||
return;
|
||||
}
|
||||
|
||||
client.update(c => {
|
||||
c.app.token = token;
|
||||
c.save();
|
||||
return c;
|
||||
});
|
||||
|
||||
get(client).getUser().then(user => {
|
||||
if (user) client.update(client => {
|
||||
client.user = user
|
||||
return client;
|
||||
});
|
||||
goto("/");
|
||||
});
|
||||
});
|
||||
}
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue