Loading Depth Study
Preparing your workspace
Protected routes verify identity and permissions before rendering private pages or performing protected operations.
Authentication in a Next.js application should work across server-rendered pages, client interactions, and server-side mutations. Public routes can remain accessible, while private areas such as dashboards or admin pages require a valid user session. Authorization must then determine whether the user can access the specific section or resource. Redirects can improve navigation, but the actual security boundary must remain on the server or database.
A student dashboard can require an authenticated student, while an admin page can require a platform admin role.
const user = await getCurrentUser();
if (!user) {
redirect('/login');
}
if (user.role !== 'admin') {
redirect('/forbidden');
}
return <AdminDashboard />;Unauthenticated users are sent to login, while authenticated users without admin permission are sent to a forbidden page.