session correction logout 3
This commit is contained in:
parent
8efc393aac
commit
89963a3a28
@ -75,7 +75,7 @@ export const authOptions: NextAuthOptions = {
|
|||||||
sameSite: 'lax',
|
sameSite: 'lax',
|
||||||
path: '/',
|
path: '/',
|
||||||
secure: process.env.NODE_ENV === 'production',
|
secure: process.env.NODE_ENV === 'production',
|
||||||
maxAge: 24 * 60 * 60 // 1 day
|
maxAge: 0 // Clear on browser close
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
callbackUrl: {
|
callbackUrl: {
|
||||||
@ -87,7 +87,7 @@ export const authOptions: NextAuthOptions = {
|
|||||||
sameSite: 'lax',
|
sameSite: 'lax',
|
||||||
path: '/',
|
path: '/',
|
||||||
secure: process.env.NODE_ENV === 'production',
|
secure: process.env.NODE_ENV === 'production',
|
||||||
maxAge: 24 * 60 * 60 // 1 day
|
maxAge: 0 // Clear on browser close
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
csrfToken: {
|
csrfToken: {
|
||||||
@ -99,7 +99,7 @@ export const authOptions: NextAuthOptions = {
|
|||||||
sameSite: 'lax',
|
sameSite: 'lax',
|
||||||
path: '/',
|
path: '/',
|
||||||
secure: process.env.NODE_ENV === 'production',
|
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 {
|
try {
|
||||||
console.log('Attempting to create/update user:', {
|
// Clear any existing session data
|
||||||
id: user.id,
|
if (typeof window !== 'undefined') {
|
||||||
email: user.email
|
localStorage.clear();
|
||||||
});
|
sessionStorage.clear();
|
||||||
|
}
|
||||||
|
|
||||||
// First check if user exists
|
// First check if user exists
|
||||||
const existingUser = await prisma.user.findUnique({
|
const existingUser = await prisma.user.findUnique({
|
||||||
where: { id: user.id }
|
where: { id: user.id }
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Existing user check:', existingUser);
|
|
||||||
|
|
||||||
// Create or update user in local database
|
// Create or update user in local database
|
||||||
const result = await prisma.user.upsert({
|
const result = await prisma.user.upsert({
|
||||||
where: { id: user.id },
|
where: { id: user.id },
|
||||||
@ -137,7 +136,6 @@ export const authOptions: NextAuthOptions = {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('User upsert result:', result);
|
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in signIn callback:', error);
|
console.error('Error in signIn callback:', error);
|
||||||
|
|||||||
@ -1,18 +1,47 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { signIn } from "next-auth/react";
|
import { signIn } from "next-auth/react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
interface SignInFormProps {
|
interface SignInFormProps {
|
||||||
callbackUrl?: string;
|
callbackUrl?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SignInForm({ callbackUrl }: SignInFormProps) {
|
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 (
|
return (
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
<h1 className="text-4xl font-bold text-white mb-4">Bienvenue sur Enkun</h1>
|
<h1 className="text-4xl font-bold text-white mb-4">Bienvenue sur Enkun</h1>
|
||||||
<p className="text-white/80 mb-8">Connectez-vous pour accéder à votre espace</p>
|
<p className="text-white/80 mb-8">Connectez-vous pour accéder à votre espace</p>
|
||||||
<button
|
<button
|
||||||
onClick={() => signIn("keycloak", { callbackUrl: callbackUrl || "/" })}
|
onClick={handleSignIn}
|
||||||
className="px-8 py-3 bg-[#0F172A] text-white rounded hover:bg-[#1E293B] transition-colors"
|
className="px-8 py-3 bg-[#0F172A] text-white rounded hover:bg-[#1E293B] transition-colors"
|
||||||
>
|
>
|
||||||
Commit
|
Commit
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user