readUser method
Reads attributes of logged in user from the AWS Cognito backend. Returns a User object with the saved attributes of the currently logged in user.
Implementation
@override
Future<User> readUser() async {
final username = await getLoggedInUsername();
if (username == null) {
throw ReadUserException(
message: 'No User logged in',
);
}
try {
final result = await _amplifyAuth.fetchUserAttributes();
_logger.fine('Successfully read user attributes: $result');
return _mapAttributesToUser(username, result);
} on aws_cognito.AuthException catch (e) {
throw ReadUserException(
message: 'Failed to read user attributes',
innerException: e,
innerStackTrace: StackTrace.current,
);
}
}