I’m writing a flutter app that interacts with some API, the first time I log in, the backend returns me a token that I save in SecureStorage. Then for each call I pass it in the header. To recover it from storage I do this:
String token = await SecureStorage.getToken();
class SecureStorage {
static const _storage = FlutterSecureStorage();
static Future<String> getToken() async {
String token = await _storage.read(key: "authToken") ?? "";
return token;
}
static Future<bool> setToken(String authToken) async {
await _storage.write(key: "authToken", value: authToken);
return true;
}
}
It has always worked, however once I put the app on testflight, we noticed that sometimes it happens that the token cannot be retrieved and therefore it is passed in vain. It seems like a question of timing. However I don’t understand why since I use await.
Could you kindly help me understand what the problem is?
Thank you!