// Given incoming request /homelet response =NextResponse.next()// Set a cookie to hide the bannerresponse.cookies.set('show-banner','false')// Response will have a `Set-Cookie:show-banner=false;path=/home` headerreturn response
// Given incoming request /homelet response =NextResponse.next()// Returns true for deleted, false is nothing is deletedresponse.cookies.delete('experiments')
import { NextResponse } from'next/server'// Given an incoming request...constloginUrl=newURL('/login',request.url)// Add ?from=/incoming-url to the /login URLloginUrl.searchParams.set('from',request.nextUrl.pathname)// And redirect to the new URLreturnNextResponse.redirect(loginUrl)
import { NextResponse } from'next/server'// Given an incoming request...constnewHeaders=newHeaders(request.headers)// Add a new headernewHeaders.set('x-version','123')// And produce a response with the new headersreturnNextResponse.next({ request: {// New request headers headers: newHeaders, },})