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