HubBar: revalidate auth on mount so the avatar shows on cold hub entry
auth.user paints from its localStorage cache, but if the hub is the entry point nothing had refreshed the session. Revalidate once (guarded on !auth.ready) so the profile picture + signed-in state are correct wherever the shared bar renders. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -3,11 +3,17 @@
|
|||||||
// /onthisday, /art, /play). Full horizontal nav on wide screens; a hamburger + drop panel
|
// /onthisday, /art, /play). Full horizontal nav on wide screens; a hamburger + drop panel
|
||||||
// on phones so the bar stays clean. `active` highlights the current section.
|
// on phones so the bar stays clean. `active` highlights the current section.
|
||||||
// News now lives at /news (the hub is `/`). `newsHref` stays overridable for safety.
|
// News now lives at /news (the hub is `/`). `newsHref` stays overridable for safety.
|
||||||
import { auth } from '$lib/auth.svelte.js';
|
import { onMount } from 'svelte';
|
||||||
|
import { auth, refresh as refreshAuth } from '$lib/auth.svelte.js';
|
||||||
import Avatar from './Avatar.svelte';
|
import Avatar from './Avatar.svelte';
|
||||||
let { active = '', newsHref = '/news' } = $props();
|
let { active = '', newsHref = '/news' } = $props();
|
||||||
let open = $state(false);
|
let open = $state(false);
|
||||||
|
|
||||||
|
// auth.user paints immediately from its localStorage cache; revalidate once if no
|
||||||
|
// page has yet (e.g. the hub is the entry point) so the avatar + signed-in state are
|
||||||
|
// correct everywhere the bar shows, not just on the feed/account pages.
|
||||||
|
onMount(() => { if (!auth.ready) refreshAuth(); });
|
||||||
|
|
||||||
// Close the menu when we cross into desktop width, so it can't linger open and reappear
|
// Close the menu when we cross into desktop width, so it can't linger open and reappear
|
||||||
// if the viewport shrinks back to mobile (the CSS hide alone left `open` stale).
|
// if the viewport shrinks back to mobile (the CSS hide alone left `open` stale).
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user