-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Errors in middleware , while calling function from lib/session
Error list:
- (middleware)/./node_modules/redis-errors/index.js
- 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*", "/"],
};