How to store auth session?
How do I store the auth session so it stops asking to me log in on every page?
2 Replies
Hi @silentnyte. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
In Refine, the authentication process is handled by the auth provider. The auth provider should have a
login
method that sets the user as authenticated and stores the necessary information (e.g., token) in the local storage. Here's an example of how an auth provider is set up in Refine with Auth0:
In your case, you should modify your handlelogin
function to use the login
method from your authProvider
. This way, refine will handle the authentication state and redirection for you.
If you want to avoid storing tokens in local storage for security reasons, you can use cookies. Here are some docs with NextJS and remix that can guide you on how to do this:
- NextJS (https://refine.dev/docs/packages/documentation/routers/nextjs/#server-side)
- Remix (https://refine.dev/docs/packages/documentation/routers/remix/#server-side-authentication-with-self-service-cookie)
Remember to restart your developer server for the changes to take effect. Press Ctrl+C on your keyboard to close the server and run npm run dev
to start it again.
Sources:
- Discord support thread: Persistent 'Loading...' Screen in Refine App (https://discord.com/channels/837692625737613362/1159178293413675032)
- How to handle node server tokens securely in refine (https://github.com/refinedev/refine/discussions/5116)
- Discord support thread: login (https://discord.com/channels/837692625737613362/1110600039929221212)
- Blog > Blog > refine vs RedwoodJS > Authentication > Refine Part 2 (https://refine.dev/blog/refine-vs-redwood-js/)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@395261846862561301> kapa.ai is still learning and improving, please let us know how it did by reacting below