浏览代码

fix(middleware): update import path for withAuth and refactor middleware function

vtugulan 6 月之前
父节点
当前提交
745b56f4f0
共有 2 个文件被更改,包括 15 次插入7 次删除
  1. 1 2
      .env.local
  2. 14 5
      middleware.ts

+ 1 - 2
.env.local

@@ -3,5 +3,4 @@ KINDE_CLIENT_ID=1863d3d354784c89a480e86410f23ea5
 KINDE_CLIENT_SECRET=OGwKvav8cRbKUNhaZup3aOmO3G4LP1Z4DIBsbXxcEShUcHAAPPLe
 KINDE_ISSUER_URL=https://vtorio.kinde.com
 KINDE_SITE_URL=http://localhost:3000
-KINDE_POST_LOGOUT_REDIRECT_URL=http://localhost:3000
-KINDE_POST_LOGIN_REDIRECT_URL=http://localhost:3000/files
+KINDE_POST_LOGOUT_REDIRECT_URL=http://localhost:3000

+ 14 - 5
middleware.ts

@@ -1,9 +1,18 @@
-import { withAuth } from "@kinde-oss/kinde-auth-nextjs/server";
+import { withAuth } from "@kinde-oss/kinde-auth-nextjs/middleware";
 
-export default function middleware(request: Request) {
-  return withAuth(request);
-}
+export default withAuth(
+  async function middleware() {
+  },
+  {
+    isReturnToCurrentPage: true,
+    // Middleware still runs on all routes, but doesn't protect the blog route
+    publicPaths: ["/"],
+  }
+);
 
 export const config = {
-  matcher: ["/files/:path*", "/api-docs/:path*", "/api/:path*", "/reference/:path*"],
+  matcher: [
+    // Run on everything but Next internals and static files
+    '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
+  ],
 };