this works really well to do lazy loading to make a performant SPA:
import dynamic from 'next/dynamic';
const DynamicComponents: Record<string, React.ComponentType<ComponentProps<any>>> = {
UserPushNotifUpdates: dynamic(() => import('@/components/dd/push-notif/push-notifs-component'), {
loading: () => <LoadingComponent />,
}),
MatchPublic: dynamic(() => import('@/components/dd/match/match-2'), {
loading: () => <LoadingComponent />,
}),
MatchPrivate: dynamic(() => import('@/components/dd/match/match'), {
loading: () => <LoadingComponent />,
}),
AdminHome: dynamic(() => import('@/components/dd/admin/home/admin-home'), {
loading: () => <LoadingComponent />,
}),
AdminDashboard: dynamic(() => import('@/components/dd/admin/dashboard/admin-dashboard'), {
loading: () => <LoadingComponent />,
}),
};
the problem is that for security anybody could load any component - I want to restrict access to components in the same way we do with pages.
To my best knowledge, with Next.js, these import calls bypass middleware.
is there a way to get the middleware to work so we can always intercept import calls to modules like this and check for access?
dynamic(() => { runMiddleware(); return Component })