I have an app with an optional login where some functionality requires the user to login.
When checking if the user is logged in I use a framework that runs an async function that requests an access token from the keychain or our server (depending on if the token needs refreshing) with a completion block telling us what to do with that information. What is the best practise for using a function like this?
- Check if the user is loggedIn when they first open the app (or bring it to the foreground) and set their login status to a global flag
- Check if the user is loggedIn when a viewController that may require authentication loads and set it to a local flag
- Call the frameworks function directly when it is needed
The first approach I fear will be inaccurate and may require I store the users accessKey in a global variable. The third approach the user will have to wait until our token request is finished.