mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2026-03-26 18:22:08 -04:00
Add login functionality to Navbar component
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { enhance } from "$app/forms";
|
||||
import { visitCount } from "$lib/utils/stores/visitCountStore";
|
||||
import { goto } from "$app/navigation";
|
||||
import type { DatabaseUser } from "$lib/server/auth";
|
||||
@@ -12,6 +13,9 @@
|
||||
async function goToFeatured() {
|
||||
goto("/featured");
|
||||
}
|
||||
async function toToLogin() {
|
||||
goto("/login");
|
||||
}
|
||||
|
||||
let count = 0;
|
||||
visitCount.subscribe((value) => {
|
||||
@@ -48,8 +52,13 @@
|
||||
</div>
|
||||
<div class="navbar-end flex justify-around md:justify-end mr-4">
|
||||
<p>Adventures: {count}</p>
|
||||
{#if !user}
|
||||
<button class="btn btn-primary ml-4" on:click={toToLogin}>Login</button>
|
||||
{/if}
|
||||
{#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}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// only show footer if scrolled to the bottom
|
||||
</script>
|
||||
|
||||
<!-- passes the user object to the navbar component -->
|
||||
<Navbar user={data.user} />
|
||||
<section>
|
||||
<slot />
|
||||
|
||||
Reference in New Issue
Block a user