Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2): improved middleware #372

Merged
merged 1 commit into from
Mar 3, 2024
Merged

feat(v2): improved middleware #372

merged 1 commit into from
Mar 3, 2024

Conversation

QuiiBz
Copy link
Owner

@QuiiBz QuiiBz commented Mar 3, 2024

Improved middleware

Previously, it was complex to use next-international's middleware with custom code or external middlewares (e.g. next-auth). The improved createI18nMiddleware function now accepts a full middleware-like signature ((request: NextRequest) => NextResponse) as the first argument, meaning you can very easily add custom logic:

Before

const I18nMiddleware = createI18nMiddleware({
  locales: ['en', 'fr'],
  defaultLocale: 'en'
})
 
export function middleware(request: NextRequest) {
  return I18nMiddleware(request)
}

After

export const middleware = createI18nMiddleware(request => {
  // Any custom logic using a raw `NextRequest` and returning a raw `NextResponse`
  return NextResponse.next()
}, {
  locales: ['en', 'fr'],
  defaultLocale: 'en'
});

@QuiiBz QuiiBz added this to the 2.0 milestone Mar 3, 2024
Copy link

vercel bot commented Mar 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
next-international ✅ Ready (Inspect) Visit Preview Mar 3, 2024 11:41am

@QuiiBz QuiiBz changed the title feat: next-international V2 feat(v2): improved middleware Mar 3, 2024
@QuiiBz QuiiBz merged commit 1c69c87 into v2 Mar 3, 2024
3 of 5 checks passed
@QuiiBz QuiiBz deleted the feat/middleware branch March 3, 2024 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant