This guide is for advanced users who want to customize how wallet
authorization details are cached and persisted. If you’re using
MobileWalletProvider with the default settings, authorization caching is
already handled for you with AsyncStorage.Overview
When a user authorizes your dApp with their wallet via MWA, the session returns anauth_token and account details. By caching these details, your app can stay “connected” across app restarts without prompting the user to re-authorize every time.
MobileWalletProvider handles this automatically with a built-in AsyncStorage cache. You can swap in your own cache implementation (e.g for encrypted storage) by passing a custom cache prop.
Both Wallet UI packages expose the same cache prop — use the tab for the one you installed. See Installation if you haven’t picked one yet.
The Cache interface
The cache prop on MobileWalletProvider accepts any object that implements the Cache<T> interface, where T is the WalletAuthorization type exported by your Wallet UI package:
get()— Retrieves the cached authorization on app startup.set(value)— Stores the authorization after the user authorizes.clear()— Removes cached authorization on disconnect/deauthorize.
Default: AsyncStorage
By default, MobileWalletProvider uses @react-native-async-storage/async-storage to persist authorization data. You don’t need to configure anything for this to work:
- @solana/kit
- @solana/web3.js
Custom cache: expo-secure-store
If you want to store authorization details in encrypted storage (e.g for sensitive auth tokens), you can create a custom cache using expo-secure-store.
Install expo-secure-store
Create a Secure Store cache
- @solana/kit
- @solana/web3.js
Cached accounts hold their address as a plain string, so the cache is a straight
JSON.stringify / JSON.parse round trip.Pass it to MobileWalletProvider
- @solana/kit
- @solana/web3.js
Using the bare MWA library
Manual caching with the MWA protocol library
Manual caching with the MWA protocol library
If you’re using the lower-level MWA protocol library directly (without
MobileWalletProvider), you’ll need to manage authorization caching yourself. The example below uses the @solana/web3.js wrapper; with the @solana/kit wrapper, cache account.address as a plain address string and drop the PublicKey conversions.Check for cached authorization
When the dApp boots up, check the cache for a prior authorization:Cache on authorize
Cache the authorization details when the user completes anauthorize request: