I'm not sure about the flow of your app but from what I understand: Users can use your app without being authenticated. However, you want unauthenticated users to have access to only a limited number of features.
You mentioned in the comments that users are required to verify their phone number on every fresh install of the app regardless of previous use. Therefore, you can use SharedPreferences to your advantage like this:
- Every time the user verifies their phone number, save a boolean value (true) to the SharedPreferences.
- When a user wants to access a feature that is only available to authenticated users, check the saved SharedPreferences boolean value to check whether the user is authenticated or not.
- When a user signs out, remember to delete/reset the SharedPreferences boolean value.
To save a boolean value to SharedPreferences, you can do something like this:
// create a SharedPreferences object and reference it with "AUTH_STATUS"
SharedPreferences sharedPreferences = getSharedPreferences("AUTH_STATUS", Context.MODE_PRIVATE);
// create an editor object from your sharedpreferences object
SharedPreferences.Editor editor = sharedPreferences.edit();
// save your boolean value to a reference called "status"
editor.putBoolean("status", true);
// save changes
editor.apply();
To retrieve a saved boolean value, you can do something like this:
// create a SharedPreferences object and reference it with "AUTH_STATUS"
SharedPreferences sharedPreferences = getSharedPreferences("AUTH_STATUS", Context.MODE_PRIVATE);
// get saved boolean value, default value should be false
boolean ab = sharedPreferences.getBoolean("status", false);
To delete/reset the SharedPreferences boolean value, simply set the boolean value to false as shown below:
// create a SharedPreferences object and reference it with "AUTH_STATUS"
SharedPreferences sharedPreferences = getSharedPreferences("AUTH_STATUS", Context.MODE_PRIVATE);
// create an editor object from your sharedpreferences object
SharedPreferences.Editor editor = sharedPreferences.edit();
// save your boolean value to a reference called "status"
editor.putBoolean("status", false);
// save changes
editor.apply();