darth0s😺
darth0s😺
KKinde
Created by darth0s😺 on 2/12/2025 in #💻┃support
How to handle root redirect before Auth and i18n case
I noticed 1 more thing. Console.log here fires only when I am logged in. So this might mean that I have to pull redirect outside the withAuth function.
export default withAuth(
async function middleware(req: NextRequest) {
let locale = await getCurrentLocale()
// Redirect from root path to locale-specific public page
console.log(`pathname: ${req.nextUrl.pathname}`)

if (req.nextUrl.pathname === '/') {
req.nextUrl.pathname = `/en/landing`;
return NextResponse.rewrite(req.nextUrl);
}

// Otherwise, handle authentication and i18n as normal
return I18nMiddleware(req);
},
{
publicPaths
}
);
export default withAuth(
async function middleware(req: NextRequest) {
let locale = await getCurrentLocale()
// Redirect from root path to locale-specific public page
console.log(`pathname: ${req.nextUrl.pathname}`)

if (req.nextUrl.pathname === '/') {
req.nextUrl.pathname = `/en/landing`;
return NextResponse.rewrite(req.nextUrl);
}

// Otherwise, handle authentication and i18n as normal
return I18nMiddleware(req);
},
{
publicPaths
}
);
5 replies
KKinde
Created by darth0s😺 on 2/12/2025 in #💻┃support
How to handle root redirect before Auth and i18n case
hi, thanks for that initial guidance. It make me think about the <AuthProvider>. Maybe the wrapper children is too high. Would appreciate results of your investigation 🙂
5 replies