From 1ee0a55cf852bf1432f316340b9f36cf59edf814 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Tue, 1 Aug 2023 18:38:33 -0700 Subject: [PATCH] fix: correct posts won't show after first login --- src/lib/auth.ts | 12 ++++++++---- src/lib/components/ui/Sidebar.svelte | 1 + src/routes/login/+page.svelte | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/lib/auth.ts b/src/lib/auth.ts index f63b5270..0e6fc12c 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -75,14 +75,14 @@ profile.subscribe(async (p) => { })) }) -export async function setUser(jwt: string, instance: string, username: string) { +export async function setUser(jwt: string, inst: string, username: string) { try { - new URL(`https://${instance}`) + new URL(`https://${inst}`) } catch (err) { return } - const user = await userFromJwt(jwt, instance) + const user = await userFromJwt(jwt, inst) if (!user) { toast({ content: 'Failed to fetch your user. Is your instance down?', @@ -90,13 +90,15 @@ export async function setUser(jwt: string, instance: string, username: string) { }) } + instance.set(inst) + profileData.update((pd) => { // too lazy to make a decent system const id = Math.floor(Math.random() * 100000) const newProfile: Profile = { id: id, - instance: instance, + instance: inst, jwt: jwt, username: username, } @@ -111,6 +113,8 @@ export async function setUser(jwt: string, instance: string, username: string) { profiles: [...pd.profiles, newProfile], } }) + + return user } async function userFromJwt( diff --git a/src/lib/components/ui/Sidebar.svelte b/src/lib/components/ui/Sidebar.svelte index a935f041..8ecdec50 100644 --- a/src/lib/components/ui/Sidebar.svelte +++ b/src/lib/components/ui/Sidebar.svelte @@ -13,6 +13,7 @@ import { profile, profileData, setUserID } from '$lib/auth.js' import { goto } from '$app/navigation' import { page } from '$app/stores' + import { slide } from 'svelte/transition' let expanded = true diff --git a/src/routes/login/+page.svelte b/src/routes/login/+page.svelte index 2f25abd0..9bdb5006 100644 --- a/src/routes/login/+page.svelte +++ b/src/routes/login/+page.svelte @@ -40,7 +40,7 @@ }) if (response?.jwt) { - setUser(response.jwt, data.instance, data.username) + await setUser(response.jwt, data.instance, data.username) toast({ content: 'Successfully logged in.', type: ToastType.success }) goto('/')