79153942

Date: 2024-11-04 01:09:54
Score: 1.5
Natty:
Report link

For the above mentioned problem, To render conditionally I would highly suggest to use conditional parallel routes(Note: parallel routes don't work as expected for dynamic routes), But for a normal route it works like a charm and is part of the layout.

Also, if possible I would suggest you to use server component and rely on server functions for auth related checks and flows. This would possible help you in following ways

  1. Decouple the logic of the component hierarchy and avoid referring the context frequently.
  2. Keeps your application in-sync with the server's state of reality rather than referring the client side state, which could potentially be stale (important especially for the auth flow)

P.S: I understand that the passed child of client component can be a server component.


Second, if you have different route paths for authenticated and un-authenticated users, then as suggested by @lalit-fauzdar in his answer, use middleware to dynamically routes the users to the respective routes.


P.S: It would be helpful if you could share the error shown.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • User mentioned (1): @lalit-fauzdar
  • Low reputation (0.5):
Posted by: JayMGurav