Global Variables in Draftbit apps are categorized in two different type of variables:
- App Variables
- Device Variables
In the App Variables menu, you can save API tokens to be used for any REST Services & Endpoints that you add to your project. The value for any App Variable is a string.
Saving API authorization in this menu, as opposed to entering it directly inside of a Fetch component, makes your app more secure by preventing your API token(s) from being exposed in each screen's code.
Access the App Variables menu by clicking the 'Settings' button on the left-hand side of the Builder and clicking the 'Global Variables' tab.
However, each time your App is restarted, the App Variable will reset to the default value. If you need to change the default value of an App Variable, you must update the value in the builder and re-publish your App.
Device Variable is a special kind of App Variable that are permanently stored on your users' devices. For example, a user's auth token is usually stored as a Device Variable. Device Variables can only be strings. You can optionally set a default value for a Device Variable (if you do not, it will default to an empty string "").
You can access Device Variables anywhere in your app you use data as a Global Variable, and they can be changed with the GlobalVariableContext Custom Code API while your app is running.
However, unlike App Variables, a Device Variable will not reset to the default value the next time the app starts. Rather, it will be the same value it was when the app last closed. Unlike App Variables, re-publishing an app currently has no effect on Device Variables.
The name of the variable to be referenced
The actual value of the variable (ex. authorization token)
Updated 19 days ago