Next.js Discord

Discord Forum

Deleting cookie in route handler skips deleting cookies after one successful deletion

Unanswered
Cinnamon posted this in #help-forum
Open in Discord
CinnamonOP
I could delete cookie in route handler with the following code
import { cookies } from 'next/headers';

export async function GET(request: Request) {
  const res = await fetch(`${process.env.API_URL}/logout`, {
    credentials: 'include',
    headers: {
      cookie: `SESSION=${cookies().get('SESSION')?.value}`,
    },
  });

  if (res.ok) {
    return new Response(null, {
      status: 302,
      headers: {
        'Set-Cookie': 'SESSION=deleted; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT',
        Location: '/',
      },
    });
  }
}


It works at first but after one successful deletion the request just skips routing handler. I'm accessing this handler using Link component.

After successful logout i re-logged in and tried logout again but this time the request just skips the router handler.

0 Replies