Skip to content

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

@ghost

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions