How to combine default exports in middleware.ts
Answered
Orinoco Crocodile posted this in #help-forum
Orinoco CrocodileOP
I have this code
But I need add another library and it requires add this code to middleware
So I have two default imports from my middleware file and how can I combine them?
Error: A module cannot have multiple default exports.
export { default } from "next-auth/middleware"
export const config = {
matcher: [
'/((?!api|_next/static|_next/image|favicon.ico|auth|page|assets).*)'
]
}But I need add another library and it requires add this code to middleware
import createMiddleware from 'next-intl/middleware';
export default createMiddleware({
locales: ['en', 'de'],
defaultLocale: 'en'
});
So I have two default imports from my middleware file and how can I combine them?
Error: A module cannot have multiple default exports.
export { default } from "next-auth/middleware"
import createMiddleware from 'next-intl/middleware';
export default createMiddleware({
locales: ['en', 'de'],
defaultLocale: 'en'
});
export const config = {
matcher: [
'/((?!api|_next/static|_next/image|favicon.ico|auth|page|assets).*)'
]
}Answered by fuma
Try using the [
withAuth](https://next-auth.js.org/configuration/nextjs#middleware) instead:import { withAuth }from "next-auth/middleware";
import createMiddleware from 'next-intl/middleware';
export default withAuth(createMiddleware({
locales: ['en', 'de'],
defaultLocale: 'en'
}));3 Replies
Try using the [
withAuth](https://next-auth.js.org/configuration/nextjs#middleware) instead:import { withAuth }from "next-auth/middleware";
import createMiddleware from 'next-intl/middleware';
export default withAuth(createMiddleware({
locales: ['en', 'de'],
defaultLocale: 'en'
}));Answer
Orinoco CrocodileOP
Thank you very much!
It is works