I am new to React Native and app development. So I am making a basic app that once opened, a modal opens up for use to login. User authenticates with Supabase, and then modal goes away to user can start using the app. The app will use the user’s data, such as his name, his privileges and things like that.
My fundamental question is, do I need to locally store the ‘session’ data and transfer it to other views/screens? or just transfer the access token and make requests to database for other interactions such as getting user details etc. How does it work generally, I think it is not down to React Native only and generally the app dev approach.
Question posted in React native
The official React Native documentation can be found here.
The official React Native documentation can be found here.
2
Answers
I suggest separate the authentication block from the rest of your code. Keep it simple by using a Context and Provider component:
and in children components, for example the login screen:
and use the data:
Usually you would want to store these things in a persisted data storage. Meaning that these data values are kept throughout different starts of the application.
Zustand Persist
State managers like the Zustand one have these functionalities. You can also use other state management libraries. However, storing the accesstoken and refreshtoken for later usage is most often a must in app development.