Open wangwailok opened 10 months ago
yeah some errors in middleware " Cannot read properties of undefined (reading 'charCodeAt')"
Full code import { NextResponse } from "next/server"; import type { NextRequest } from "next/server"; import { session } from "./lib/session";
export default async function middleware(request: NextRequest) {
const token = await session().all(); console.log(token, 'token<--------------') 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*", "/"],
solve this mr.package owner @wangwailok , @Zeryther @majidkuhail
I want to do some protected route, but middlware in App Route seems cannot get the session on server.
`export default async function middleware(req: NextRequest) {
//always shows {} const session = useServerSession(); return intlMiddleware(req); }`