Redirect logic
Answered
Irish Terrier posted this in #help-forum
Irish TerrierOP
Hi! I have a landing page, and an auth button. When a user is authenticated, I want to redirect them to a /user page, meaning that they are not able to open the landing page. Where is the perfect location to put a redirect logic in the app?
11 Replies
@Irish Terrier do you use server actions for auth?
if your landing page, you can put redirection logic before rendering the UI.
Answer
in your case
redirect("/user");Irish TerrierOP
Thanks @James4u ! Yeah, I know there are a variety of options, but I thought maybe I should put it inside the
but I think your proposal is better and I should leave it on a page level
middleware.tsbut I think your proposal is better and I should leave it on a page level
sure, and by middleware.ts you mean the global middleware?
Irish TerrierOP
yeah. i wasn't sure if it was a good from the architectural point of view
but as far as i can tell, this is a decent solution. not sure if it's the best
yeah, if you are on app router - no way to doubt this approach
please mark solution if everything is clear 😅
Irish TerrierOP
let's gooo
thanks @James4u
thanks @James4u