Skip to content

Instantly share code, notes, and snippets.

@salihgueler
Created May 11, 2023 15:37
Show Gist options
  • Save salihgueler/d8dddab95876a88f79cd05352ae8be11 to your computer and use it in GitHub Desktop.
Save salihgueler/d8dddab95876a88f79cd05352ae8be11 to your computer and use it in GitHub Desktop.
Future<void> main() async {
final user = await getCurrentUsernameAndEmailWithNamedParameters();
print('Username is ${user.username}');
print('Email is ${user.email}');
final anotherUser = await getCurrentUsernameAndEmailWithNamedParameters();
print('Username is ${anotherUser.$1}');
print('Email is ${anotherUser.$2}');
}
Future<({String username, String email})> getCurrentUsernameAndEmailWithNamedParameters() async {
({String username, String email}) userRecord;
final authenticatedUser = await Amplify.Auth.getCurrentUser();
final currentCognitoUser = await Amplify.Auth.fetchUserAttributes();
final email= currentCognitoUser.firstWhere(
(element) {
return element.userAttributeKey == CognitoUserAttributeKey.email;
},
).value;
userRecord = (username: authenticatedUser.username, email: email);
return userRecord;
}
Future<(String, String)> getCurrentUsernameAndEmailWithoutParameters() async {
(String, String) userRecord;
final authenticatedUser = await Amplify.Auth.getCurrentUser();
final currentCognitoUser = await Amplify.Auth.fetchUserAttributes();
final email= currentCognitoUser.firstWhere(
(element) {
return element.userAttributeKey == CognitoUserAttributeKey.email;
},
).value;
userRecord = (authenticatedUser.username, email);
return userRecord;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment