fix: Enhance logout cookie deletion to cover more NextAuth cookie variants and adjust the logout sequence, and disable prefetching for footer links.
This commit is contained in:
@@ -6,6 +6,7 @@ export async function clearAuthCookies() {
|
|||||||
const cookieStore = await cookies();
|
const cookieStore = await cookies();
|
||||||
|
|
||||||
// Delete all next-auth v5 cookie variants
|
// Delete all next-auth v5 cookie variants
|
||||||
|
// Must specify path and secure options to match how they were set
|
||||||
const cookieNames = [
|
const cookieNames = [
|
||||||
'authjs.session-token',
|
'authjs.session-token',
|
||||||
'authjs.csrf-token',
|
'authjs.csrf-token',
|
||||||
@@ -13,10 +14,36 @@ export async function clearAuthCookies() {
|
|||||||
'__Secure-authjs.session-token',
|
'__Secure-authjs.session-token',
|
||||||
'__Secure-authjs.csrf-token',
|
'__Secure-authjs.csrf-token',
|
||||||
'__Secure-authjs.callback-url',
|
'__Secure-authjs.callback-url',
|
||||||
|
// next-auth v4 fallback names
|
||||||
|
'next-auth.session-token',
|
||||||
|
'next-auth.csrf-token',
|
||||||
|
'next-auth.callback-url',
|
||||||
|
'__Secure-next-auth.session-token',
|
||||||
|
'__Secure-next-auth.csrf-token',
|
||||||
|
'__Secure-next-auth.callback-url',
|
||||||
|
// Host-prefixed variants (used when behind a proxy)
|
||||||
|
'__Host-authjs.csrf-token',
|
||||||
|
'__Host-next-auth.csrf-token',
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const name of cookieNames) {
|
for (const name of cookieNames) {
|
||||||
cookieStore.delete(name);
|
// Delete with explicit options to ensure cookie is actually removed
|
||||||
|
cookieStore.delete({
|
||||||
|
name,
|
||||||
|
path: '/',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also try getting all cookies and deleting any auth-related ones
|
||||||
|
const allCookies = cookieStore.getAll();
|
||||||
|
for (const cookie of allCookies) {
|
||||||
|
if (
|
||||||
|
cookie.name.includes('authjs') ||
|
||||||
|
cookie.name.includes('next-auth') ||
|
||||||
|
cookie.name.includes('session-token')
|
||||||
|
) {
|
||||||
|
cookieStore.delete({ name: cookie.name, path: '/' });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
|
|||||||
@@ -25,8 +25,14 @@ export default function LogoutPage() {
|
|||||||
localStorage.removeItem('refreshToken');
|
localStorage.removeItem('refreshToken');
|
||||||
localStorage.removeItem('user');
|
localStorage.removeItem('user');
|
||||||
|
|
||||||
|
// Delete httpOnly cookies via server action FIRST
|
||||||
|
// This ensures the session cookie is gone before signOut triggers session checks
|
||||||
|
await clearAuthCookies();
|
||||||
|
|
||||||
|
// Client-side signOut to clear NextAuth client state
|
||||||
await signOut({ redirect: false });
|
await signOut({ redirect: false });
|
||||||
// Delete httpOnly cookies via server action (Next.js cookies() API)
|
|
||||||
|
// Delete cookies again after signOut in case signOut recreated any
|
||||||
await clearAuthCookies();
|
await clearAuthCookies();
|
||||||
|
|
||||||
// Redirect to login immediately
|
// Redirect to login immediately
|
||||||
|
|||||||
@@ -98,9 +98,10 @@ export function Footer() {
|
|||||||
</h3>
|
</h3>
|
||||||
<ul className="space-y-3">
|
<ul className="space-y-3">
|
||||||
{footerLinks.services.links.map((link) => (
|
{footerLinks.services.links.map((link) => (
|
||||||
<li key={link.href}>
|
<li key={link.label}>
|
||||||
<Link
|
<Link
|
||||||
href={link.href}
|
href={link.href}
|
||||||
|
prefetch={false}
|
||||||
className="font-serif font-normal text-[14px] leading-[19px] text-[#00293D] hover:text-[#e58625] transition-colors"
|
className="font-serif font-normal text-[14px] leading-[19px] text-[#00293D] hover:text-[#e58625] transition-colors"
|
||||||
>
|
>
|
||||||
{link.label}
|
{link.label}
|
||||||
@@ -117,9 +118,10 @@ export function Footer() {
|
|||||||
</h3>
|
</h3>
|
||||||
<ul className="space-y-3">
|
<ul className="space-y-3">
|
||||||
{footerLinks.serviceProviders.links.map((link) => (
|
{footerLinks.serviceProviders.links.map((link) => (
|
||||||
<li key={link.href}>
|
<li key={link.label}>
|
||||||
<Link
|
<Link
|
||||||
href={link.href}
|
href={link.href}
|
||||||
|
prefetch={false}
|
||||||
className="font-serif font-normal text-[14px] leading-[19px] text-[#00293D] hover:text-[#e58625] transition-colors"
|
className="font-serif font-normal text-[14px] leading-[19px] text-[#00293D] hover:text-[#e58625] transition-colors"
|
||||||
>
|
>
|
||||||
{link.label}
|
{link.label}
|
||||||
@@ -136,9 +138,10 @@ export function Footer() {
|
|||||||
</h3>
|
</h3>
|
||||||
<ul className="space-y-3">
|
<ul className="space-y-3">
|
||||||
{footerLinks.resources.links.map((link) => (
|
{footerLinks.resources.links.map((link) => (
|
||||||
<li key={link.href}>
|
<li key={link.label}>
|
||||||
<Link
|
<Link
|
||||||
href={link.href}
|
href={link.href}
|
||||||
|
prefetch={false}
|
||||||
className="font-serif font-normal text-[14px] leading-[19px] text-[#00293D] hover:text-[#e58625] transition-colors"
|
className="font-serif font-normal text-[14px] leading-[19px] text-[#00293D] hover:text-[#e58625] transition-colors"
|
||||||
>
|
>
|
||||||
{link.label}
|
{link.label}
|
||||||
@@ -155,9 +158,10 @@ export function Footer() {
|
|||||||
</h3>
|
</h3>
|
||||||
<ul className="space-y-3">
|
<ul className="space-y-3">
|
||||||
{footerLinks.aboutContact.links.map((link) => (
|
{footerLinks.aboutContact.links.map((link) => (
|
||||||
<li key={link.href}>
|
<li key={link.label}>
|
||||||
<Link
|
<Link
|
||||||
href={link.href}
|
href={link.href}
|
||||||
|
prefetch={false}
|
||||||
className="font-serif font-normal text-[14px] leading-[19px] text-[#00293D] hover:text-[#e58625] transition-colors"
|
className="font-serif font-normal text-[14px] leading-[19px] text-[#00293D] hover:text-[#e58625] transition-colors"
|
||||||
>
|
>
|
||||||
{link.label}
|
{link.label}
|
||||||
@@ -209,7 +213,7 @@ export function Footer() {
|
|||||||
<div className="max-w-7xl mx-auto px-6 py-4">
|
<div className="max-w-7xl mx-auto px-6 py-4">
|
||||||
<div className="flex flex-col md:flex-row items-center justify-between gap-4">
|
<div className="flex flex-col md:flex-row items-center justify-between gap-4">
|
||||||
<p className="font-serif font-normal text-[15px] leading-[21px] text-[#00293D]">Copyright © 2025 Your Agency Name. All rights reserved.</p>
|
<p className="font-serif font-normal text-[15px] leading-[21px] text-[#00293D]">Copyright © 2025 Your Agency Name. All rights reserved.</p>
|
||||||
<Link href="/privacy-policy" className="font-serif font-normal text-[15px] leading-[21px] text-[#00293D] hover:text-[#e58625] transition-colors">
|
<Link href="/privacy-policy" prefetch={false} className="font-serif font-normal text-[15px] leading-[21px] text-[#00293D] hover:text-[#e58625] transition-colors">
|
||||||
Privacy Policy
|
Privacy Policy
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user