Skip to content

Commit

Permalink
fix: auth bug (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobLinCool authored Feb 24, 2025
1 parent 29d69d4 commit bb15d61
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const authHandle: Handle = async ({ event, resolve }) => {
if (
event.url.pathname.startsWith('/api') &&
!event.url.pathname.startsWith('/api/auth/signin') &&
!event.url.pathname.startsWith('/api/auth/signout') &&
!event.locals.user
) {
return new Response(JSON.stringify({ error: 'Unauthorized' }), {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/Auth.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</script>

{#if $user}
<div>
<div class="flex items-center space-x-4">
<p class="inline-block">Welcome, {$profile?.displayName || $user.displayName}!</p>
<Button href="/dashboard" color="primary">Dashboard</Button>
</div>
Expand Down
5 changes: 4 additions & 1 deletion src/lib/stores/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const user = writable<User | null>(null);

// Listen to auth state changes
auth.onAuthStateChanged((newUser) => {
console.log('Auth state changed:', newUser);
user.set(newUser);
});

Expand Down Expand Up @@ -45,7 +46,9 @@ export async function signInWithGoogle() {
// Sign out function
export async function signOut(f: typeof fetch = fetch) {
try {
await auth.signOut();
if (auth.currentUser) {
await auth.signOut();
}
// Clear the session cookie
await f('/api/auth/signout', { method: 'POST' });
// Redirect to home page
Expand Down

0 comments on commit bb15d61

Please sign in to comment.