diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index 80fddd0e..df46d5cf 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -1,7 +1,7 @@ import NextAuth, { NextAuthOptions } from "next-auth"; import KeycloakProvider from "next-auth/providers/keycloak"; import { prisma } from '@/lib/prisma'; -import { ExtendedJWT, ExtendedSession, ServiceToken, invalidateServiceTokens } from '@/lib/session'; +import { ExtendedJWT, ExtendedSession, ServiceToken, invalidateServiceTokens, clearAllCookies } from '@/lib/session'; import { Session } from "next-auth"; declare module "next-auth" { @@ -55,7 +55,7 @@ export const authOptions: NextAuthOptions = { ], session: { strategy: "jwt", - maxAge: 24 * 60 * 60, // 1 day + maxAge: 8 * 60 * 60, // 8 hours }, cookies: { sessionToken: { @@ -67,7 +67,7 @@ export const authOptions: NextAuthOptions = { sameSite: 'lax', path: '/', secure: process.env.NODE_ENV === 'production', - maxAge: 24 * 60 * 60 // 1 day + maxAge: 8 * 60 * 60 // 8 hours } }, callbackUrl: { @@ -79,7 +79,7 @@ export const authOptions: NextAuthOptions = { sameSite: 'lax', path: '/', secure: process.env.NODE_ENV === 'production', - maxAge: 24 * 60 * 60 // 1 day + maxAge: 8 * 60 * 60 // 8 hours } }, csrfToken: { @@ -91,7 +91,7 @@ export const authOptions: NextAuthOptions = { sameSite: 'lax', path: '/', secure: process.env.NODE_ENV === 'production', - maxAge: 24 * 60 * 60 // 1 day + maxAge: 8 * 60 * 60 // 8 hours } } }, @@ -177,14 +177,20 @@ export const authOptions: NextAuthOptions = { accessToken: extendedToken.accessToken ?? '', refreshToken: extendedToken.refreshToken, serviceTokens: extendedToken.serviceTokens ?? {}, - expires: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(), + expires: new Date(Date.now()).toISOString(), // Expire immediately } as ExtendedSession); + + // Force clear all cookies on signout + if (typeof window !== 'undefined') { + clearAllCookies(); + } } } }, pages: { signIn: '/signin', error: '/signin', + signOut: '/signin', // Redirect to signin after signout }, debug: process.env.NODE_ENV === 'development', }; diff --git a/app/signout/page.tsx b/app/signout/page.tsx new file mode 100644 index 00000000..5ece52c6 --- /dev/null +++ b/app/signout/page.tsx @@ -0,0 +1,10 @@ +import { SignOutHandler } from "@/components/auth/signout-handler"; + +export default function SignOut() { + return ( +
Déconnexion en cours...
+