May i can switch this in middleware ?
Unanswered
Ninhache posted this in #help-forum
NinhacheOP
Here's a component :
Simplified component.. but yes this is a component, to redirect to the great route, do you think i can move this the middleware ?
I feel i can't because i'm getting the user's role from the session
export default async function DashboardPage() {
const { role } = await getServerSession(authOptions)
if (!role) {
redirect('/login')
}
switch(role.toLowerCase()) {
case 'artiste':
case 'organisateur':
case 'admin':
redirect(`/dashboard/${role.toLowerCase()}`)
break;
default:
}
return (
<></>
);
}Simplified component.. but yes this is a component, to redirect to the great route, do you think i can move this the middleware ?
I feel i can't because i'm getting the user's role from the session
13 Replies
i dont feel like you need to
don't forget to redirect on
default:@alfon i dont feel like you need to
NinhacheOP
Mh.. i wanted to move it to middleware to ease the implementation of i18n
because in my middleware, i intent to parse request to know which trad i've to use..
If i'm on the route
If i'm on the route
/en/dashboard, dashboard should be in english and so onah fair enough
NinhacheOP
since there's no real plugin to handle it correctly, i've to do this in the middleware :/
@alfon ah fair enough
NinhacheOP
And then.. i can't use the session.. or i'm wrong?
@alfon why not?
NinhacheOP
because...? Idk how i could get the session 

Japanese anchovy
it should be in the request headers which you have access to in the middleware
NinhacheOP
i've to try i didnt find it yet.. and i'm stuck on something else rn