Hard
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 540 times
Edit
1
Community EvaluationsNo one has reviewed this question yet, be the first!
7
What is the path to the about page in Next.js?6
What are the benefits of using dynamic imports in Next.js?3
Fetch the product details from the server on every request and cache it.10
Load blog post data at build time for a static render.7
How to use Incremental Static Regeneration (ISR) in Next.js to update blog posts periodically after their initial publication.3
Add global middleware to handle authentication across all routes in your application in Next.js3
Create a NextJS page with a navbar and a footer