How to getUser without doing a server request on every page.
I am following the guide on https://tahazsh.com/blog/building-a-solidjs-app-from-scratch/ (expanding on the session in the https://start.solidjs.com/advanced/session) to create a authentication system in SolidJS Start. It works fine but it loads the if i want to use in a page, it dose a POST request to the backend server each time the page is loaded. How can i cache the user in the client, that also updates if the user logs out.
The get user, i though i could add it to the token, but i would have to redirect the user with the new headder to store it.
In react without SSR, it would just store the user in local storage, would that also be the right way to do here, as i guess that would cause problems with the SSR?
5 Replies
Have a look at this for some inspiration:
https://github.com/zentered/auth0-solid-start
It's using a createCookieSessionStorage to persist the session:
https://start.solidjs.com/api/createCookieSessionStorage
GitHub
GitHub - zentered/auth0-solid-start: Auth0 authentication for Solid...
Auth0 authentication for Solid SSR. Contribute to zentered/auth0-solid-start development by creating an account on GitHub.
SolidStart Beta Docuentation
SolidStart Beta Documentation
Early release documentation and resources for SolidStart Beta
Protected | Auth.js
When Using SSR
I have looked into the Auth.js but it seems to have the same issue in that i actually need to do a server call to get the user each place i need it.
GitHub
Move common client types to core remove tsup createSession ho...
NOTE:
It's a good idea to open an issue first to discuss potential changes.
Please make sure that you are NOT opening a PR to fix a potential security vulnerability. Instead, please follow the...
Wait for this pr to get merged it has a createSession hook
Which is a client side hook to get the current logged in user