1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-30 02:09:37 +02:00

Add login functionality to Navbar component

This commit is contained in:
Sean Morley 2024-04-05 22:22:09 +00:00
parent 3ab2918ed2
commit cd11ce2d97
2 changed files with 11 additions and 1 deletions

View file

@ -1,4 +1,5 @@
<script lang="ts"> <script lang="ts">
import { enhance } from "$app/forms";
import { visitCount } from "$lib/utils/stores/visitCountStore"; import { visitCount } from "$lib/utils/stores/visitCountStore";
import { goto } from "$app/navigation"; import { goto } from "$app/navigation";
import type { DatabaseUser } from "$lib/server/auth"; import type { DatabaseUser } from "$lib/server/auth";
@ -12,6 +13,9 @@
async function goToFeatured() { async function goToFeatured() {
goto("/featured"); goto("/featured");
} }
async function toToLogin() {
goto("/login");
}
let count = 0; let count = 0;
visitCount.subscribe((value) => { visitCount.subscribe((value) => {
@ -48,8 +52,13 @@
</div> </div>
<div class="navbar-end flex justify-around md:justify-end mr-4"> <div class="navbar-end flex justify-around md:justify-end mr-4">
<p>Adventures: {count}</p> <p>Adventures: {count}</p>
{#if !user}
<button class="btn btn-primary ml-4" on:click={toToLogin}>Login</button>
{/if}
{#if user} {#if user}
<p>Hello {user.first_name}</p> <form method="post" use:enhance>
<button class="btn btn-primary ml-4">Sign out</button>
</form>
{/if} {/if}
</div> </div>
</div> </div>

View file

@ -6,6 +6,7 @@
// only show footer if scrolled to the bottom // only show footer if scrolled to the bottom
</script> </script>
<!-- passes the user object to the navbar component -->
<Navbar user={data.user} /> <Navbar user={data.user} />
<section> <section>
<slot /> <slot />