login method Null safety
Description
Logs in to an existing account with the given password
. During production, this method retrieves the keys from the keychain using address
. Both of these params are required in order
to return a successful LoginResponse
.
Example
final res = await MotorFlutter.to.login(password: 'terrible-password-123', did: 'did:snr:abc123');
if (res == null) {
throw Exception('Login failed');
}
print('Account logged in successfully: ${res.address}');
Next Steps:
- Define a new blockchain verifiable data model using createSchema
- Buy a .snr/ subdomain to simplify your account address using buyAlias
- Connect to the p2p network and enable secure device-to-devce communication with connect
- ADR-1
Implementation
Future<LoginResponse?> login({required String password, required String address}) async {
final auth = await readKeysForAddr(address);
if (auth == null) {
throw Exception('No keys found for did: $address');
}
final resp = await MotorFlutterPlatform.instance.loginWithKeys(LoginWithKeysRequest(
did: address,
password: password,
aesDscKey: auth.item1,
aesPskKey: auth.item2,
));
if (resp != null) {
this.address(resp.whoIs.owner);
didDocument.value = resp.whoIs.didDocument;
authorized.value = true;
}
return resp;
}