session-reset-fix
This commit is contained in:
parent
6b87cc9a34
commit
bdb4f7a370
|
@ -86,14 +86,17 @@ export const AuthorView = (props: Props) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
createEffect(async () => {
|
createEffect(async () => {
|
||||||
console.error('[AuthorView] load subscriptions')
|
const slug = author()?.slug
|
||||||
try {
|
if (slug) {
|
||||||
const { authors, topics } = await fetchSubscriptions()
|
console.debug('[AuthorView] load subscriptions')
|
||||||
setFollowing([...(authors || []), ...(topics || [])])
|
try {
|
||||||
const userSubscribers = await apiClient.getAuthorFollowers({ slug: author().slug })
|
const { authors, topics } = await fetchSubscriptions()
|
||||||
setFollowers(userSubscribers)
|
setFollowing([...(authors || []), ...(topics || [])])
|
||||||
} catch (error) {
|
const userSubscribers = await apiClient.getAuthorFollowers({ slug })
|
||||||
console.error('[AuthorView] error:', error)
|
setFollowers(userSubscribers)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[AuthorView] error:', error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -165,20 +165,21 @@ export const SessionProvider = (props: {
|
||||||
}
|
}
|
||||||
if (!author()) {
|
if (!author()) {
|
||||||
const a = await loadAuthor()
|
const a = await loadAuthor()
|
||||||
await loadSubscriptions()
|
if (!a) reset()
|
||||||
if (a) {
|
else await loadSubscriptions()
|
||||||
console.log('[context.session] author profile and subs loaded', author())
|
|
||||||
} else {
|
|
||||||
setSubscriptions(EMPTY_SUBSCRIPTIONS)
|
|
||||||
setAuthor(null)
|
|
||||||
console.warn('[context.session] author is not loaded')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setIsSessionLoaded(true)
|
setIsSessionLoaded(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const reset = () => {
|
||||||
|
setIsSessionLoaded(true)
|
||||||
|
setSubscriptions(EMPTY_SUBSCRIPTIONS)
|
||||||
|
setSession(null)
|
||||||
|
setAuthor(null)
|
||||||
|
}
|
||||||
|
|
||||||
// initial effect
|
// initial effect
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const metaRes = await authorizer().getMetaData()
|
const metaRes = await authorizer().getMetaData()
|
||||||
|
@ -189,11 +190,7 @@ export const SessionProvider = (props: {
|
||||||
} catch {
|
} catch {
|
||||||
console.warn('[context.session] load session failed')
|
console.warn('[context.session] load session failed')
|
||||||
}
|
}
|
||||||
if (!s) {
|
if (!s) reset()
|
||||||
setIsSessionLoaded(true)
|
|
||||||
setSession(null)
|
|
||||||
setAuthor(null)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// callback state updater
|
// callback state updater
|
||||||
|
@ -236,7 +233,7 @@ export const SessionProvider = (props: {
|
||||||
|
|
||||||
const signOut = async () => {
|
const signOut = async () => {
|
||||||
await authorizer().logout()
|
await authorizer().logout()
|
||||||
setSession(null)
|
reset()
|
||||||
showSnackbar({ body: t("You've successfully logged out") })
|
showSnackbar({ body: t("You've successfully logged out") })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user