Thanks to React's context mechanism we can access auth data in the whole application. You can find
Context is provided inside
App.ts file for the whole app thanks to wrapping
Auth data is stored in encrypted storage. It is read on app start via
useEffect to fill up context state.
Reading data from
In any component, you can access
AuthContext. Thanks to TypeScript autocomplete you'll see what methods and fields you can use.
const authContext = useContext(AuthContext)
const isLoggedIn = !!authContext.state?.token
Writing data to
To change values inside the state you need to call one of the available methods
Both methods are
async as they are accessing data on device drive. Tokens are stored inside an encrypted container (see: react-native-keychain) on devices disk.
This method saves tokens & additional data to secure storage.
This method removes tokens & additional data from secure storage.