#nextjs app router - browser data
1 messages · Page 1 of 1 (latest)
Hi @storm jewel. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Next.js provides several ways to manage and clear data stored in the browser, such as cookies. However, it does not directly provide methods to clear other types of browser data like IndexedDB, cache, or localStorage. These are typically managed using standard JavaScript APIs provided by the browser.
For cookies, you can use the cookies API in Next.js to get, set, and delete cookies. Here's an example of how to delete a cookie:
import { cookies } from 'next/headers'
export async function exampleAction() {
// Delete cookie
cookies().delete('name')
}
You can also delete cookies inside an API Route using the setHeader method on the response:
import type { NextApiRequest, NextApiResponse } from 'next'
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
res.setHeader('Set-Cookie', 'username=; Path=/; HttpOnly; Max-Age=0')
res.status(200).send('Cookie has been deleted.')
}