session correction logout 3 rest
This commit is contained in:
parent
89963a3a28
commit
bf63b48c28
@ -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);
|
||||
|
||||
@ -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 (
|
||||
<div className="text-center">
|
||||
<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>
|
||||
<button
|
||||
onClick={handleSignIn}
|
||||
onClick={() => signIn("keycloak", { callbackUrl: callbackUrl || "/" })}
|
||||
className="px-8 py-3 bg-[#0F172A] text-white rounded hover:bg-[#1E293B] transition-colors"
|
||||
>
|
||||
Commit
|
||||
|
||||
@ -349,12 +349,7 @@ export function MainNav() {
|
||||
))}
|
||||
<DropdownMenuItem
|
||||
className="text-white/80 hover:text-white hover:bg-black/50 cursor-pointer"
|
||||
onClick={async () => {
|
||||
await signOut({
|
||||
callbackUrl: '/signin',
|
||||
redirect: true
|
||||
});
|
||||
}}
|
||||
onClick={() => signOut()}
|
||||
>
|
||||
<LogOut className="mr-2 h-4 w-4" />
|
||||
<span>Déconnexion</span>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user