signIn method

Future<UserInfo?> signIn(
  1. String email,
  2. String password
)

Attempts to sign in with email and password. If successful, a UserInfo is returned. If the attempt is not a success, null is returned.

Implementation

Future<UserInfo?> signIn(String email, String password) async {
  try {
    var serverResponse = await caller.email.authenticate(email, password);
    if (!serverResponse.success ||
        serverResponse.userInfo == null ||
        serverResponse.keyId == null ||
        serverResponse.key == null) {
      if (kDebugMode) {
        print(
          'serverpod_auth_email: Failed to authenticate with '
          'Serverpod backend: '
          '${serverResponse.failReason ?? 'reason unknown'}'
          '. Aborting.',
        );
      }
      return null;
    }

    // Authentication was successful, store the key.
    var sessionManager = await SessionManager.instance;
    sessionManager.registerSignedInUser(
      serverResponse.userInfo!,
      serverResponse.keyId!,
      serverResponse.key!,
    );
    return serverResponse.userInfo;
  } catch (e, stackTrace) {
    if (kDebugMode) {
      print('$e');
      print('$stackTrace');
    }
    return null;
  }
}