diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index ab5a9a7f..eb32e495 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: 0 // Clear on browser close + maxAge: 24 * 60 * 60 // 1 day } }, callbackUrl: { @@ -87,7 +87,7 @@ export const authOptions: NextAuthOptions = { sameSite: 'lax', path: '/', secure: process.env.NODE_ENV === 'production', - maxAge: 0 // Clear on browser close + maxAge: 24 * 60 * 60 // 1 day } }, csrfToken: { @@ -99,7 +99,7 @@ export const authOptions: NextAuthOptions = { sameSite: 'lax', path: '/', secure: process.env.NODE_ENV === 'production', - maxAge: 0 // Clear on browser close + maxAge: 24 * 60 * 60 // 1 day } } }, @@ -111,17 +111,18 @@ export const authOptions: NextAuthOptions = { } try { - // Clear any existing session data - if (typeof window !== 'undefined') { - localStorage.clear(); - sessionStorage.clear(); - } + console.log('Attempting to create/update user:', { + id: user.id, + email: user.email + }); // 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 }, @@ -136,6 +137,7 @@ 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 53c43170..a577b35f 100644 --- a/components/auth/signin-form.tsx +++ b/components/auth/signin-form.tsx @@ -1,47 +1,18 @@ "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