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 {
|
try {
|
||||||
new URL(`https://${instance}`)
|
new URL(`https://${inst}`)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await userFromJwt(jwt, instance)
|
const user = await userFromJwt(jwt, inst)
|
||||||
if (!user) {
|
if (!user) {
|
||||||
toast({
|
toast({
|
||||||
content: 'Failed to fetch your user. Is your instance down?',
|
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) => {
|
profileData.update((pd) => {
|
||||||
// too lazy to make a decent system
|
// too lazy to make a decent system
|
||||||
const id = Math.floor(Math.random() * 100000)
|
const id = Math.floor(Math.random() * 100000)
|
||||||
|
|
||||||
const newProfile: Profile = {
|
const newProfile: Profile = {
|
||||||
id: id,
|
id: id,
|
||||||
instance: instance,
|
instance: inst,
|
||||||
jwt: jwt,
|
jwt: jwt,
|
||||||
username: username,
|
username: username,
|
||||||
}
|
}
|
||||||
@@ -111,6 +113,8 @@ export async function setUser(jwt: string, instance: string, username: string) {
|
|||||||
profiles: [...pd.profiles, newProfile],
|
profiles: [...pd.profiles, newProfile],
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
async function userFromJwt(
|
async function userFromJwt(
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
import { profile, profileData, setUserID } from '$lib/auth.js'
|
import { profile, profileData, setUserID } from '$lib/auth.js'
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
|
import { slide } from 'svelte/transition'
|
||||||
|
|
||||||
let expanded = true
|
let expanded = true
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (response?.jwt) {
|
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 })
|
toast({ content: 'Successfully logged in.', type: ToastType.success })
|
||||||
goto('/')
|
goto('/')
|
||||||
|
|||||||
Reference in new issue
Block a user