im using in my backend with jsonwebtoken to create jwt then i want in nextjs middleware in the front and to verify the token but jsonwebtoken not working in client render so can i use jose or any other library to verify this token or i must to create the token with jose also in the backend
import { jwtVerify } from "jose";
const secret: any = process.env.JWT_SECRET!;
export const config = {
matcher: ["/((?!api|_next|fonts|500|examples|[\\w-]+\\.\\w+).*)"],
};
export default function middleware(req: NextRequest) {
const url = req.url;
const token: any = req.cookies.get("token");
const urlToken = req.nextUrl.searchParams.get("token")!;
if (url.includes("/auth")) {
if (token === undefined) {
return NextResponse.next();
}
if (token)
try {
console.log(token);
const verify = jwtVerify(token, secret);
console.log(verify);
return NextResponse.redirect("http://localhost:3000/");
} catch (e) {
return NextResponse.next();
}
}
}