feat: session deletion, improved tasting deletion visibility, and PWA login loop fix

This commit is contained in:
2025-12-18 21:02:44 +01:00
parent a4a9d79c4c
commit a64e8f17a1
8 changed files with 174 additions and 32 deletions

View File

@@ -28,6 +28,7 @@ export default async function BottlePage({
}
}
const supabase = createServerComponentClient({ cookies });
const { data: { user } } = await supabase.auth.getUser();
const { data: bottle } = await supabase
.from('bottles')
@@ -187,7 +188,7 @@ export default async function BottlePage({
{/* List */}
<div className="lg:col-span-2">
<TastingList initialTastings={tastings || []} />
<TastingList initialTastings={tastings || []} currentUserId={user?.id} />
</div>
</div>
</section>

View File

@@ -25,16 +25,22 @@ export default function Home() {
const checkUser = async () => {
try {
const { data: { session }, error } = await supabase.auth.getSession();
console.log('Initial session check:', session ? 'User logged in' : 'No session');
console.log('[Auth] Initial session check:', {
hasSession: !!session,
userId: session?.user?.id,
email: session?.user?.email,
error: error?.message
});
if (error) {
console.error('Session retrieval error:', error);
console.error('[Auth] Session retrieval error:', error);
}
setUser(session?.user ?? null);
if (session?.user) {
fetchCollection();
}
} catch (err) {
console.error('Fatal error checking user:', err);
console.error('[Auth] Fatal error checking user:', err);
setUser(null);
} finally {
setIsLoading(false);
@@ -45,10 +51,17 @@ export default function Home() {
// Listen for auth changes
const { data: { subscription } } = supabase.auth.onAuthStateChange((event, session) => {
console.log('Auth state change:', event, session?.user ? 'User logged in' : 'No user');
console.log('[Auth] State change event:', event, {
hasSession: !!session,
userId: session?.user?.id,
email: session?.user?.email
});
setUser(session?.user ?? null);
if (session?.user) {
fetchCollection();
if (event === 'SIGNED_IN' || event === 'INITIAL_SESSION' || event === 'TOKEN_REFRESHED') {
fetchCollection();
}
} else {
setBottles([]);
}

View File

@@ -4,6 +4,7 @@ import React, { useState, useEffect } from 'react';
import { createClientComponentClient } from '@supabase/auth-helpers-nextjs';
import { ChevronLeft, Users, Calendar, GlassWater, Plus, Trash2, Loader2, Sparkles, ChevronRight, Play, Square } from 'lucide-react';
import Link from 'next/link';
import { deleteSession } from '@/services/delete-session';
import { useSession } from '@/context/SessionContext';
import { useParams, useRouter } from 'next/navigation';
import { useI18n } from '@/i18n/I18nContext';
@@ -48,6 +49,7 @@ export default function SessionDetailPage() {
const [isLoading, setIsLoading] = useState(true);
const { activeSession, setActiveSession } = useSession();
const [isAddingParticipant, setIsAddingParticipant] = useState(false);
const [isDeleting, setIsDeleting] = useState(false);
useEffect(() => {
fetchSessionData();
@@ -131,6 +133,23 @@ export default function SessionDetailPage() {
}
};
const handleDeleteSession = async () => {
if (!confirm('Möchtest du diese Session wirklich löschen? Alle Verknüpfungen gehen verloren.')) return;
setIsDeleting(true);
const result = await deleteSession(id as string);
if (result.success) {
if (activeSession?.id === id) {
setActiveSession(null);
}
router.push('/');
} else {
alert(result.error);
setIsDeleting(false);
}
};
if (isLoading) {
return (
<div className="min-h-screen flex items-center justify-center bg-zinc-50 dark:bg-black">
@@ -206,6 +225,15 @@ export default function SessionDetailPage() {
Session Stoppen
</button>
)}
<button
onClick={handleDeleteSession}
disabled={isDeleting}
title="Session löschen"
className="p-3 bg-red-50 dark:bg-red-900/10 text-red-600 dark:text-red-400 rounded-2xl hover:bg-red-600 hover:text-white dark:hover:bg-red-600 dark:hover:text-white transition-all border border-red-100 dark:border-red-900/20 disabled:opacity-50"
>
{isDeleting ? <Loader2 size={20} className="animate-spin" /> : <Trash2 size={20} />}
</button>
</div>
</div>
</header>