// 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
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)