How to decode a token in Next.js middleware?

Viewed 34

I am setting an encoded cookie in one of my nextjs component

setCookie("_SYS_USER_AUTH", window.btoa(res?.data));

I want to access the same in Nextjs middleware like this

export function middleware(request) {
  const { cookies, url } = request;
  const jwt = cookies.get(`_SYS_USER_AUTH`);
  if (request.nextUrl.pathname.startsWith("/account")) {
     console.log(window.btoa(jwt));
  }
}

Here I am getting window is not defined error. Is there any other way I can decode this in nextjs middleware?

0 Answers
Related