I'm trying to delete a cookie using the next/headers module in a Next.js application, but it doesn't seem to work as expected. Here's the code snippet:
import {cookies} from "next/headers";
export default async function Signout() {
async function deleteTokens() {
"use server"
cookies().delete('accessToken')
}
await deleteTokens()
return (
<></>
);
}
I expected the cookies().delete('accessToken') line to delete the cookie named "accessToken", but it doesn't seem to have any effect. The cookie is still present after the function is executed.
I am getting following error: Error: Cookies can only be modified in a Server Action or Route Handler. Read more: https://nextjs.org/docs/app/api-reference/functions/cookies#cookiessetname-value-options
But i have set the "use server" and enabled it in the next.config.js
#using Next.js 13.4.4
from Unable to delete cookie using Next.js server side action
No comments:
Post a Comment