From 8ffa573a073c75399bdb10f91831316a62a2f0e1 Mon Sep 17 00:00:00 2001
From: Craig Kaiser <craig@bestpractical.com>
Date: Sun, 6 Oct 2024 14:14:21 -0400
Subject: [PATCH] update header on auth change

---
 src/components/Header.svelte    | 3 ++-
 src/routes/auth/+page.server.ts | 7 +++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/components/Header.svelte b/src/components/Header.svelte
index 8010262..9977dec 100644
--- a/src/components/Header.svelte
+++ b/src/components/Header.svelte
@@ -16,7 +16,8 @@
 		currentUser = await supabase.auth.getUser();
 	}
 
-	supabase.auth.onAuthStateChange(() => {
+	supabase.auth.onAuthStateChange((event) => {
+		console.log(event);
 		getCurrentUser();
 	});
 </script>
diff --git a/src/routes/auth/+page.server.ts b/src/routes/auth/+page.server.ts
index 163b438..317c5bf 100644
--- a/src/routes/auth/+page.server.ts
+++ b/src/routes/auth/+page.server.ts
@@ -25,14 +25,17 @@ export const actions = {
 
 		const { email, password } = form.data;
 		const { error } = await supabase.auth.signInWithPassword({ email, password });
-		console.log(error);
 
 		if (error) {
 			console.log(error);
 			return setError(form, 'email', error.message);
 		}
 
-		return { signInForm: form, success: true };
+		// Instead of returning the form directly, redirect or trigger a session update
+		// Option 1: Redirect after signing in
+		return { success: true, redirect: '/protected-routes/dashboard' };
+
+		// Option 2: You could set a session variable or state that the UI listens to
 	},
 
 	resetpassword: async ({ request, locals: { supabase } }) => {