diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index eb32e495..ab5a9a7f 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -75,7 +75,7 @@ export const authOptions: NextAuthOptions = { sameSite: 'lax', path: '/', secure: process.env.NODE_ENV === 'production', - maxAge: 24 * 60 * 60 // 1 day + maxAge: 0 // Clear on browser close } }, callbackUrl: { @@ -87,7 +87,7 @@ export const authOptions: NextAuthOptions = { sameSite: 'lax', path: '/', secure: process.env.NODE_ENV === 'production', - maxAge: 24 * 60 * 60 // 1 day + maxAge: 0 // Clear on browser close } }, csrfToken: { @@ -99,7 +99,7 @@ export const authOptions: NextAuthOptions = { sameSite: 'lax', path: '/', secure: process.env.NODE_ENV === 'production', - maxAge: 24 * 60 * 60 // 1 day + maxAge: 0 // Clear on browser close } } }, @@ -111,18 +111,17 @@ export const authOptions: NextAuthOptions = { } try { - console.log('Attempting to create/update user:', { - id: user.id, - email: user.email - }); + // Clear any existing session data + if (typeof window !== 'undefined') { + localStorage.clear(); + sessionStorage.clear(); + } // First check if user exists const existingUser = await prisma.user.findUnique({ where: { id: user.id } }); - console.log('Existing user check:', existingUser); - // Create or update user in local database const result = await prisma.user.upsert({ where: { id: user.id }, @@ -137,7 +136,6 @@ export const authOptions: NextAuthOptions = { }, }); - console.log('User upsert result:', result); return true; } catch (error) { console.error('Error in signIn callback:', error); diff --git a/components/auth/signin-form.tsx b/components/auth/signin-form.tsx index a577b35f..53c43170 100644 --- a/components/auth/signin-form.tsx +++ b/components/auth/signin-form.tsx @@ -1,18 +1,47 @@ "use client"; import { signIn } from "next-auth/react"; +import { useRouter } from "next/navigation"; +import { useEffect } from "react"; interface SignInFormProps { callbackUrl?: string; } export function SignInForm({ callbackUrl }: SignInFormProps) { + const router = useRouter(); + + useEffect(() => { + // Clear any existing session data + localStorage.clear(); + sessionStorage.clear(); + }, []); + + const handleSignIn = async () => { + try { + // Clear any existing session data before signing in + localStorage.clear(); + sessionStorage.clear(); + + const result = await signIn("keycloak", { + callbackUrl: callbackUrl || "/", + redirect: true + }); + + if (result?.error) { + console.error('Sign in error:', result.error); + } + } catch (error) { + console.error('Sign in error:', error); + } + }; + return (
Connectez-vous pour accéder à votre espace