apiConfigured method
Checks if the API is configured by verifying the presence of user, password, and clientIdentifier in secure storage.
Returns true
if all values are present and credentials are set successfully,
otherwise returns false
.
Implementation
Future<bool> apiConfigured() async {
final user = await getValueFromSecureStorage(
key: 'user',
);
final password = await getValueFromSecureStorage(
key: 'password',
);
final clientIdentifier = await getValueFromSecureStorage(
key: 'clientIdentifier',
);
if (user == null || password == null || clientIdentifier == null) {
return false;
}
final response = await setCredentials(
user: user,
password: password,
clientIdentifier: int.parse(clientIdentifier),
);
if (response.isLeft()) {
return false;
}
final groupKeyA = await getValueFromSecureStorage(
key: 'groupKeyA',
);
final groupKeyB = await getValueFromSecureStorage(
key: 'groupKeyB',
);
final parsedGroupKeyA = int.tryParse(groupKeyA ?? '');
if (parsedGroupKeyA == null || parsedGroupKeyA == 0) {
await clearGroupKeyA();
} else {
await addGroupKeyA(groupKeyA: parsedGroupKeyA);
}
final parsedGroupKeyB = int.tryParse(groupKeyB ?? '');
if (parsedGroupKeyB == null || parsedGroupKeyB == 0) {
await clearGroupKeyB();
} else {
await addGroupKeyB(groupKeyB: parsedGroupKeyB);
}
return response.asRight;
}