next.js:_middleware with nextresponse blodering的图像
这个问题扩展了这个问题。 Next.js中的_middleware带有import {nextresponse}从“ Next/Server”;
可用于JWT身份验证,但会阻止所有包括图像的路由。这意味着,如果您想通过CSS或图像在重定向路由中加载的图像,则不会加载。下面的代码封锁地址栏重定向并允许图像加载。访问令牌可能会更好
This question extends this question. The _middleware in Next.js with import { NextResponse } from "next/server";
can be used for JWT authentication but blocks all the routes including images. This means that if you have images that you want to load in the redirect route by CSS or Image, will not load. The code below blocks address bar redirect and allows image load. Access Token would probably be better
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新:经过一些调试后,这就是我想到的。我编写的先前代码不会让您在登录后重定向到主页。原因是_middleware似乎在 /api /登录之前运行并基于预先条件,只需将它们重定向到登录,然后返回void(_Middleware'in Redirect上)。
此更新的代码允许 /api /登录无需刷新令牌即可进行路由,如果它们在没有令牌的情况下浏览地址栏,则将其发送回登录
Update: after some debugging, this is what I've come up with. The previous code that I wrote does not let you be redirected to the home page after login. The reason being that the _Middleware seems to runs before /api/login and based on the prev conditional, just redirects them to the login again and returns void (_Middleware "includes" on redirect).
This updated code allows /api/login to be routed on without a refresh token and sends them back to login if they navigate through address bar without a token
项目中的每条路线将调用中间件。以下是执行订单:
a href =“ https://nextjs.org/docs/advanced-features/middleware” rel =“ nofollow noreferrer”>以获取更多信息
Middleware will be invoked for every route in your project. The following is the execution order:
There are two ways to define which paths Middleware will run on:
for more informations