#How to run a function only during SSR?

3 messages · Page 1 of 1 (latest)

wanton valve
#

Hey,
I would like to validate the user's token during SSR. When the token is valid the client is considered authenticated and no more token validation is necessary while navigating on the client side.
I don't know how to run the isTokenValid function only on during SSR and skip it during client-side navigation. Both of:

  • onRequest
  • routeLoader$
    is triggered on every client-side navigation which is not desired.

🙏 Any ideas?

placid galleon
#

I think that you could use onGet

wanton valve
#

onGet would run on every client-side navigation so that's not what I need.

I think I need a counterpart of useVisibleTask$. Something like useServerTask$ which would run only when a component is mounted on the server. But as there isn't such a hook I don't think I can achieve my goal.