未捕获的语法错误:意外的令牌'< ' Next.js中间件

yebdmbv4  于 2023-08-04  发布在  其他
关注(0)|答案(1)|浏览(108)

Next.js版本:13.4.7 Node.js版本v18.16.0

import { NextRequest, NextResponse } from 'next/server';
import jwtDecode from 'jwt-decode';

export function middleware(request: NextRequest) {
  const accessToken = request.cookies.has('accessToken');
  const isLoginPage = request.nextUrl.pathname === '/login';

  if (!isLoginPage && !accessToken) {
    return NextResponse.redirect(new URL('/login', request.url));
  }
  return null;
}

export const config = {
  matcher: [
    '/',
    '/login',
    '/dashboard',
    '/dashboard/:path*',
    '/:path*/admin/:path*',
  ],
};

字符串
我还访问了不同的论坛stackoverflow,github,但没有一个解决方案对我有效。

plupiseo

plupiseo1#

重写
/:path*/admin/:path*

/admin/:path*

相关问题