Skip to content

Commit 300bf70

Browse files
authored
Merge pull request #20 from encryption4all/feat/nav-logged-in-state
feat(nav): show logged-in state in marketing header
2 parents 9f12bd8 + 5eace1b commit 300bf70

3 files changed

Lines changed: 59 additions & 6 deletions

File tree

src/lib/components/Header.svelte

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44
import logoLight from '$lib/assets/images/logo.svg';
55
import logoDark from '$lib/assets/images/logo-dark.svg';
66
7+
type AuthProp =
8+
| { loggedIn: true; email: string | null; portalHref: string }
9+
| { loggedIn: false; email: null; portalHref: string };
10+
711
let {
812
showPricing = true,
9-
showRegister = true
13+
showRegister = true,
14+
auth = { loggedIn: false, email: null, portalHref: '/portal/dashboard' }
1015
}: {
1116
showPricing?: boolean;
1217
showRegister?: boolean;
18+
auth?: AuthProp;
1319
} = $props();
1420
1521
let menuOpen = $state(false);
@@ -37,7 +43,14 @@
3743
{#each navLinks as link}
3844
<a href={link.href}>{link.label}</a>
3945
{/each}
40-
<a href="/auth/login" class="nav-login">Log in</a>
46+
{#if auth.loggedIn}
47+
{#if auth.email}
48+
<span class="nav-user" aria-label="Signed in as {auth.email}">{auth.email}</span>
49+
{/if}
50+
<a href={auth.portalHref} class="nav-login">My portal</a>
51+
{:else}
52+
<a href="/auth/login" class="nav-login">Log in</a>
53+
{/if}
4154
</nav>
4255

4356
<div class="header-actions">
@@ -58,7 +71,14 @@
5871
{#each navLinks as link}
5972
<a href={link.href} onclick={() => (menuOpen = false)}>{link.label}</a>
6073
{/each}
61-
<a href="/auth/login" onclick={() => (menuOpen = false)}>Log in</a>
74+
{#if auth.loggedIn}
75+
{#if auth.email}
76+
<span class="mobile-user">{auth.email}</span>
77+
{/if}
78+
<a href={auth.portalHref} onclick={() => (menuOpen = false)}>My portal</a>
79+
{:else}
80+
<a href="/auth/login" onclick={() => (menuOpen = false)}>Log in</a>
81+
{/if}
6282
</nav>
6383
{/if}
6484
</header>
@@ -124,6 +144,16 @@
124144
font-weight: var(--pg-font-weight-bold);
125145
}
126146
147+
.nav-user {
148+
font-family: var(--pg-font-family);
149+
font-size: var(--pg-font-size-sm);
150+
color: var(--pg-text-secondary);
151+
max-width: 240px;
152+
overflow: hidden;
153+
text-overflow: ellipsis;
154+
white-space: nowrap;
155+
}
156+
127157
@media only screen and (max-width: 768px) {
128158
display: none;
129159
}
@@ -146,6 +176,13 @@
146176
padding: 0.5rem 1.5rem 1rem;
147177
border-top: 1px solid var(--pg-strong-background);
148178
179+
.mobile-user {
180+
font-family: var(--pg-font-family);
181+
font-size: var(--pg-font-size-sm);
182+
color: var(--pg-text-secondary);
183+
padding: 0.75rem 0 0.25rem;
184+
}
185+
149186
a {
150187
font-family: var(--pg-font-family);
151188
font-size: var(--pg-font-size-lg);
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
import type { LayoutServerLoad } from './$types';
22
import { isEnabled } from '$lib/feature-flags';
3+
import { ATTR } from '$lib/server/auth/yivi';
4+
5+
export const load: LayoutServerLoad = async ({ locals }) => {
6+
const session = locals.session;
7+
const auth = session
8+
? {
9+
loggedIn: true as const,
10+
email: session.yiviAttributes?.[ATTR.email] ?? null,
11+
portalHref:
12+
session.userType === 'admin' ? '/admin/organizations' : '/portal/dashboard'
13+
}
14+
: { loggedIn: false as const, email: null, portalHref: '/portal/dashboard' };
315

4-
export const load: LayoutServerLoad = async () => {
516
return {
617
marketingFlags: {
718
pricing: isEnabled('pricingPage'),
819
registration: isEnabled('registration')
9-
}
20+
},
21+
auth
1022
};
1123
};

src/routes/(marketing)/+layout.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
let { data, children }: { data: LayoutData; children: import('svelte').Snippet } = $props();
77
</script>
88

9-
<Header showPricing={data.marketingFlags.pricing} showRegister={data.marketingFlags.registration} />
9+
<Header
10+
showPricing={data.marketingFlags.pricing}
11+
showRegister={data.marketingFlags.registration}
12+
auth={data.auth}
13+
/>
1014
<main>
1115
{@render children()}
1216
</main>

0 commit comments

Comments
 (0)