Currently, I am attempting to utilize MiddleWare in conjunction with Next.js's Middleware and JWT.
Upon logging cookies
and the typeof cookies
variable, this is what I see on my console:
{
token: 'token='myToken'; Path=/'
}
object
Below is the code that I am working with:
import { NextRequest, NextResponse } from "next/server";
import { verify } from "jsonwebtoken";
const SECRET = process.env.SECRET;
export function middleware(req, res) {
const cookies = req.cookies;
const url = req.url;
if (url.includes("/admin")) {
console.log(cookies)
console.log(typeof cookies)
}
return NextResponse.next();
}
However, when attempting to access the token
property using cookies.token
, it returns undefined
.
Any insights into what might be causing this issue?