login method
Send login request to kuzzle with credentials
If login success, store the jwt into kuzzle object
Implementation
Future<String?> login(String strategy, Map<String, dynamic> credentials,
{String? expiresIn}) async =>
kuzzle
.query(KuzzleRequest(
controller: name,
action: 'login',
strategy: strategy,
expiresIn: expiresIn,
body: credentials,
))
.then((response) {
try {
kuzzle.jwt = response.result['jwt'] as String?;
kuzzle.emit(KuzzleEvents.LOGIN_ATTEMPT, [], {
const Symbol('success'): true,
});
return kuzzle.jwt;
} on Exception {
rethrow;
}
}).catchError((error) {
kuzzle.emit(KuzzleEvents.LOGIN_ATTEMPT, [], {
const Symbol('success'): false,
const Symbol('error'): error,
});
throw error as Error;
});