I am currently working on implementing a redirect feature in next.js 13 when the jwt back-end is not received. This is being done with the appdir
activated.
This is the code in my middleware.ts file:
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
export function middleware(req: NextRequest) {
const token = req.cookies.get('token')
if (!token) {
return NextResponse.redirect('/login')
}
return NextResponse.next()
}