fix: correct posts won't show after first login
This commit is contained in:
1 parent
7aaaa6d163
commit
1ee0a55cf8
3 files changed
+10
-5
No files matched your search
+8
-4
@@ -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(
|
||||
|
||||
@@ -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
|
||||
</script>
|
||||
|
||||
@@ -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('/')
|
||||
|
||||
Reference in new issue
Block a user