Created
May 11, 2023 15:37
-
-
Save salihgueler/d8dddab95876a88f79cd05352ae8be11 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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