session correction logout 3 rest
This commit is contained in:
parent
50cf9ca06b
commit
0f3818bb99
@ -1,7 +1,7 @@
|
|||||||
import NextAuth, { NextAuthOptions } from "next-auth";
|
import NextAuth, { NextAuthOptions } from "next-auth";
|
||||||
import KeycloakProvider from "next-auth/providers/keycloak";
|
import KeycloakProvider from "next-auth/providers/keycloak";
|
||||||
import { prisma } from '@/lib/prisma';
|
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";
|
import { Session } from "next-auth";
|
||||||
|
|
||||||
declare module "next-auth" {
|
declare module "next-auth" {
|
||||||
@ -55,7 +55,7 @@ export const authOptions: NextAuthOptions = {
|
|||||||
],
|
],
|
||||||
session: {
|
session: {
|
||||||
strategy: "jwt",
|
strategy: "jwt",
|
||||||
maxAge: 24 * 60 * 60, // 1 day
|
maxAge: 8 * 60 * 60, // 8 hours
|
||||||
},
|
},
|
||||||
cookies: {
|
cookies: {
|
||||||
sessionToken: {
|
sessionToken: {
|
||||||
@ -67,7 +67,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: 8 * 60 * 60 // 8 hours
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
callbackUrl: {
|
callbackUrl: {
|
||||||
@ -79,7 +79,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: 8 * 60 * 60 // 8 hours
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
csrfToken: {
|
csrfToken: {
|
||||||
@ -91,7 +91,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: 8 * 60 * 60 // 8 hours
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -177,14 +177,20 @@ export const authOptions: NextAuthOptions = {
|
|||||||
accessToken: extendedToken.accessToken ?? '',
|
accessToken: extendedToken.accessToken ?? '',
|
||||||
refreshToken: extendedToken.refreshToken,
|
refreshToken: extendedToken.refreshToken,
|
||||||
serviceTokens: extendedToken.serviceTokens ?? {},
|
serviceTokens: extendedToken.serviceTokens ?? {},
|
||||||
expires: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
|
expires: new Date(Date.now()).toISOString(), // Expire immediately
|
||||||
} as ExtendedSession);
|
} as ExtendedSession);
|
||||||
|
|
||||||
|
// Force clear all cookies on signout
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
clearAllCookies();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
pages: {
|
pages: {
|
||||||
signIn: '/signin',
|
signIn: '/signin',
|
||||||
error: '/signin',
|
error: '/signin',
|
||||||
|
signOut: '/signin', // Redirect to signin after signout
|
||||||
},
|
},
|
||||||
debug: process.env.NODE_ENV === 'development',
|
debug: process.env.NODE_ENV === 'development',
|
||||||
};
|
};
|
||||||
|
|||||||
10
app/signout/page.tsx
Normal file
10
app/signout/page.tsx
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { SignOutHandler } from "@/components/auth/signout-handler";
|
||||||
|
|
||||||
|
export default function SignOut() {
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen flex items-center justify-center">
|
||||||
|
<SignOutHandler />
|
||||||
|
<p>Déconnexion en cours...</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
24
components/auth/signout-handler.tsx
Normal file
24
components/auth/signout-handler.tsx
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { signOut } from "next-auth/react";
|
||||||
|
import { clearAllCookies } from "@/lib/session";
|
||||||
|
|
||||||
|
export function SignOutHandler() {
|
||||||
|
useEffect(() => {
|
||||||
|
const handleSignOut = async () => {
|
||||||
|
// Clear all cookies first
|
||||||
|
clearAllCookies();
|
||||||
|
|
||||||
|
// Then sign out from NextAuth
|
||||||
|
await signOut({
|
||||||
|
callbackUrl: "/signin",
|
||||||
|
redirect: true
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
handleSignOut();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user