diff --git a/src/components/Views/Author/Author.tsx b/src/components/Views/Author/Author.tsx index 2cca6646..6a81e58a 100644 --- a/src/components/Views/Author/Author.tsx +++ b/src/components/Views/Author/Author.tsx @@ -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) + } } }) diff --git a/src/context/session.tsx b/src/context/session.tsx index b12d228b..f49d4652 100644 --- a/src/context/session.tsx +++ b/src/context/session.tsx @@ -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") }) }