middleware render two times in dynamic routes
Unanswered
Transvaal lion posted this in #help-forum
Transvaal lionOP
I have a simple middleware, why in dynamic routes it runs two times?
I want to only run once because i need to refresh token.
middleware: GET /admin/agencys/a736d0c0-3db2-4bca-9d78-b9267e9406d2
middleware: GET /admin/agencys/a736d0c0-3db2-4bca-9d78-b9267e9406d2
GET /admin/agencys/a736d0c0-3db2-4bca-9d78-b9267e9406d2 200 in 62ms
GET /admin/agencys/a736d0c0-3db2-4bca-9d78-b9267e9406d2 200 in 47ms
I want to only run once because i need to refresh token.
middleware: GET /admin/agencys/a736d0c0-3db2-4bca-9d78-b9267e9406d2
middleware: GET /admin/agencys/a736d0c0-3db2-4bca-9d78-b9267e9406d2
GET /admin/agencys/a736d0c0-3db2-4bca-9d78-b9267e9406d2 200 in 62ms
GET /admin/agencys/a736d0c0-3db2-4bca-9d78-b9267e9406d2 200 in 47ms
17 Replies
Asiatic Lion
Hello, i have the same problem : (
Transvaal lionOP
No, same problem
middleware: GET /admin/agencys/9b4244bd-963e-4675-aff7-a9e034914ff8
middleware: GET /admin/agencys/9b4244bd-963e-4675-aff7-a9e034914ff8
GET /admin/agencys/9b4244bd-963e-4675-aff7-a9e034914ff8 200 in 70ms
GET /admin/agencys/9b4244bd-963e-4675-aff7-a9e034914ff8 200 in 47ms
middleware: GET /admin/agencys/9b4244bd-963e-4675-aff7-a9e034914ff8
GET /admin/agencys/9b4244bd-963e-4675-aff7-a9e034914ff8 200 in 70ms
GET /admin/agencys/9b4244bd-963e-4675-aff7-a9e034914ff8 200 in 47ms
This is the logs
this is the middleware:
export async function middleware(request) {
console.log('middleware:', request.method, request.nextUrl.pathname);
}
export const config = {
matcher: ["/admin", "/admin/:path((?!_next|api|.\..).)", "/login", '/((?!_next|static).)'],
};
export async function middleware(request) {
console.log('middleware:', request.method, request.nextUrl.pathname);
}
export const config = {
matcher: ["/admin", "/admin/:path((?!_next|api|.\..).)", "/login", '/((?!_next|static).)'],
};
but i want to this middleware only run on admin
But stills the same
I make a middleware to refresh token, and get this problem because it refresh two times and i get a error
But then i simplify the middleware and saw that he runs 2 times only in dynamic routes i think
yes, it is
Asiatic Lion
yes is the same as me
Transvaal lionOP
Is a long project ahaha
With authentication
Can we call?
Ok np
Falas portugues?
Original message was deleted
Beveren
This is why titles mean nothing in companies. A so called "Lead Developer" should know middleware isnt built for slow data fetching. Its not a full session manager and it sure as hell isnt your authorization layer.