Can you prevent parts of the client side code being sent to unauthenticated clients?
Unanswered
Hairy Woodpecker posted this in #help-forum
Hairy WoodpeckerOP
Some of my client side code needs to only be sent to users that have authenticated. Is there a why to ensure the certain routes are only sent to authenticated users? If not I'll create two apps: unauthenticated app and authenticated app
6 Replies
yes
In the page where you want only authenticated users to view, you can add a condition
before sending over the tsx
@Hairy Woodpecker you can also do an auth check in the proxy.ts if your auth provider is only checking headers not the db. That way users can be bounce b4 anything on the page loads, but you should also protect your routes b4 it fetches any data should also do an auth check your route or server function should not be returning data to a client that isnt authed if the data is sensitive or user related.
I would avoid auth checks on the page and do it inside the data fetch, this works better for streaming or cache components while also bouncing non authed users on the proxy. proxy.ts happens on the edge so it will not show a flash when bouncing users it will just load the redirect b4 anything on the route is shown
if you want the user to be abel to be on the page but not show certin data I would do an auth check in the route or server function and handle what ever you return gracefully on the client. You can retrun null or [] then handle that when you resolve the data