Next intl middleware error
Unanswered
Red wood ant posted this in #help-forum
Red wood antOP
Hi, I wanted to add a second middleware to handle my authentication redirect, but when I add the second middleware, I encounter this error. How can I fix it?
Error: Unable to find
import createMiddleware from 'next-intl/middleware';
import { NextResponse, NextRequest } from 'next/server'
export default createMiddleware({
// A list of all locales that are supported
locales: ['en', 'pl'],
// Used when no locale matches
defaultLocale: 'en',
});
export const config = {
// Match only internationalized pathnames
matcher: ['/((?!api|_next|_vercel|.*\\..*).*)'],
};
export function middleware(request:NextRequest){
const accessToken = request.cookies.get('accessToken')
if(accessToken && ['/'].includes(request.nextUrl.pathname)){
return NextResponse.redirect(new URL('/home', request.url))
}
}Error: Unable to find
next-intl locale because the middleware didn't run on this request. See https://next-intl-docs.vercel.app/docs/routing/middleware#unable-to-find-locale12 Replies
currently it's not supported to use multiple middlewares @Red wood ant
@Red wood ant solved?
Red wood antOP
Nope still i didnt i dont know how to cope with it
Every time when I want to add another thing to my middleware I have this error @B33fb0n3
I would like to remain this intl
@Red wood ant Every time when I want to add another thing to my middleware I have this error <@301376057326567425>
you could implement something like
https://next-auth.js.org/configuration/nextjs#advanced-usage
withAuth in next-authhttps://next-auth.js.org/configuration/nextjs#advanced-usage
Red wood antOP
Ok i will try to do it later
Thank you guys
@Red wood ant Ok i will try to do it later
or you can just use it if you are using next-auth😀
Red wood antOP
i am using jwt with express xd