getCurrentUser method

Future<AuthUser> getCurrentUser({
  1. GetCurrentUserOptions? options,
})

Retrieves the current active user.

Optionally accepts plugin options which allow customizing provider-specific behavior.

For more information, see the Amplify docs.

Examples

import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
Future<String?> getCurrentUserId() async {
  try {
    final user = await Amplify.Auth.getCurrentUser();
    return user.userId;
  } on AuthException catch (e) {
    safePrint('Could not retrieve current user: ${e.message}');
    return null;
  }
}

Implementation

Future<AuthUser> getCurrentUser({
  GetCurrentUserOptions? options,
}) =>
    identifyCall(
      AuthCategoryMethod.getCurrentUser,
      () => defaultPlugin.getCurrentUser(options: options),
    );