Reputation: 16168
I have a ReactNative app that is working with some constants,
export const BEARER_TOKEN = 'eyJhbGciOiJIU***'
The app works fine until I need to update the token so with a new version distributed by appcenter,
If I just update the app, it keeps the old token
but
If I delete and install a new version, the new token is used
So, how can I make sure that the new token gets loaded? like if the app starts reload constants?
Thanks.
Upvotes: 0
Views: 359
Reputation: 818
I suggest using Asyncstorage and Redux state in order to maintain your Bearer_Token.
For instance, assume using the Facebook app. You are logging in for the very first time. Capture and store your Bearer_token in Asyncstorage and also maintain in the redux state.
Next time when you kill the app and open again. Load the Bearer_Token from Asyncstorage.
Your Bearer_Token will be set dynamically.
Upvotes: 1
Reputation: 3805
You can't, with this approach. This is the nature of javascript, it loads everything initially and even if you change it by putting the variable in object. It is a bad practice.
The better approach is to use redux or context api,
I see you want to use BEARER_TOKEN, for user authentication probably.
So you can have a state, authUser
inside your redux and it will keep track of the token in your entire app. This approach is very useful when you want the user to logout if any change in authToken
.
For a simple version, you can use context api
from react.
now the third option, If you really really really want to not use these approaches.
You can just usewindow.token = 'sdfasdf'
;
then whenever you want to change it, just use window.token = 'soemthing else'
from other files.
Upvotes: 1