feat(*): Add sign in route with redirection to mydex

This commit is contained in:
Josh Creek
2024-07-14 21:37:24 +01:00
parent 1a6232f5bd
commit 2db9045d3d
3 changed files with 188 additions and 146 deletions
+4
View File
@@ -137,6 +137,7 @@
> >
</button> </button>
<div class="dropdown dropdown-end"> <div class="dropdown dropdown-end">
{#if localUser}
<div tabindex="0" role="button" class="btn btn-ghost btn-circle avatar"> <div tabindex="0" role="button" class="btn btn-ghost btn-circle avatar">
<div class="w-10 rounded-full"> <div class="w-10 rounded-full">
<img alt="usericon" src="/OIG5.jpg" /> <img alt="usericon" src="/OIG5.jpg" />
@@ -159,6 +160,9 @@
<li><SignIn {supabase} on:signedIn={getUser} /></li> <li><SignIn {supabase} on:signedIn={getUser} /></li>
{/if} {/if}
</ul> </ul>
{:else}
<a href="/signin">Sign In</a>
{/if}
</div> </div>
</div> </div>
</div> </div>
+6 -2
View File
@@ -149,6 +149,9 @@
<title>Living Dex Tracker - My Dex</title> <title>Living Dex Tracker - My Dex</title>
</svelte:head> </svelte:head>
{#if !localUser}
<p>Please <a href="/signin" class="underline text-primary hover:text-secondary">sign in</a></p>
{:else}
<div class="flex"> <div class="flex">
<aside class="w-64 bg-gray-800 text-white p-4 fixed h-5/6"> <aside class="w-64 bg-gray-800 text-white p-4 fixed h-5/6">
<h2 class="text-2xl font-semibold mb-4">Filters</h2> <h2 class="text-2xl font-semibold mb-4">Filters</h2>
@@ -266,8 +269,8 @@
{:else} {:else}
<h1>Failed to load</h1> <h1>Failed to load</h1>
<p> <p>
If you're seeing this, you probably haven't created your Pokédex data yet. Please do so If you're seeing this, you probably haven't created your Pokédex data yet. Please do
by clicking this button. so by clicking this button.
</p> </p>
<button class="btn" on:click={createCatchRecords}>Create Pokédex data</button> <button class="btn" on:click={createCatchRecords}>Create Pokédex data</button>
{/if} {/if}
@@ -280,3 +283,4 @@
</div> </div>
</main> </main>
</div> </div>
{/if}
+34
View File
@@ -0,0 +1,34 @@
<script lang="ts">
import { onDestroy } from 'svelte';
import { user } from '$lib/stores/user.js';
import { type User } from '@supabase/auth-js';
import SignIn from '$lib/components/SignIn.svelte';
import { goto } from '$app/navigation';
export let data;
let { supabase } = data;
$: ({ supabase } = data);
let localUser: User | null;
const unsubscribe = user.subscribe((value) => {
localUser = value;
});
onDestroy(unsubscribe);
async function getUser() {
const {
data: { session }
} = await supabase.auth.getSession();
if (session) {
localUser = session.user;
} else {
localUser = null;
}
user.set(localUser);
goto('/mydex', { replace: true });
}
</script>
<SignIn {supabase} on:signedIn={getUser} />