Medium
You are working on an app, which implements a redirection functionality based on the user's role. The application has an app folder structure with adashboard
folder for authenticated users. You have aroute.js
file inapp/dashboard
that handles the redirection logic based on the user role.
import{ redirect, permanentRedirect } from 'next/navigation';
export async function route({ session }){
if(!session || !session.user){
return redirect('/login');
}
if(session.user.role !== 'admin'){
return permanentRedirect('/unauthorized');
}
// Continue with rendering the dashboard for the admin
//...
}
// In this context,`session` is an object containing the user's session information.
Regarding the above scenario and code, what statement(s) is/are correct about handling redirects in Next.js with the App Router?
Author: AnasStatus: PublishedQuestion passed 275 times
Edit
1
Community EvaluationsNo one has reviewed this question yet, be the first!
Similar QuestionsMore questions about Next JS
6
Load blog post data at build time for a static render.4
What is the path to the about page in Next.js?2
What are the benefits of using dynamic imports in Next.js?2
How to use Incremental Static Regeneration (ISR) in Next.js to update blog posts periodically after their initial publication.2
How to manipulate HTTP response headers within a `getServerSideProps` function in Next.js