next-app-session icon indicating copy to clipboard operation
next-app-session copied to clipboard

TypeError: Cannot read properties of undefined (reading 'charCodeAt')

Open ghost opened this issue 9 months ago • 1 comments

Errors in middleware , while calling function from lib/session Error list:

  1. (middleware)/./node_modules/redis-errors/index.js
  2. TypeError: Cannot read properties of undefined (reading 'charCodeAt')

Full code : import { NextResponse } from "next/server"; import type { NextRequest } from "next/server"; import { getSession } from "./lib/session";

export default async function middleware(request: NextRequest) { const accessToken = await getSession("token"); console.log(accessToken, 'accessToken<-------------------')

const { pathname } = request.nextUrl;

if (accessToken && pathname === "/") { return NextResponse.redirect(new URL("/account/dashboard", request.url)); }

if (accessToken && pathname.startsWith("/account")) { return NextResponse.redirect(new URL("/login", request.url)); }

return NextResponse.next(); }

export const config = { matcher: ["/account/:path*", "/"], };

@majidkuhail @Zeryther

ghost avatar May 23 '24 08:05 ghost