loginEmailAccount static method

Future<Map<String, dynamic>> loginEmailAccount({
  1. required String email,
  2. required String password,
})

Returns a map with the following keys: if there was no error:

  • session: Session from Appwrite if there was an error:
  • error: true if there was an error
  • type: error if there was an error
  • message: String containing the error message
  • code: int containing the error code

Implementation

static Future<Map<String, dynamic>> loginEmailAccount({
  /// Email of the user to login
  required String email,

  /// Password for the email
  required String password,
}) async {
  Account account = Account(_client);
  try {
    final models.Session session = await account.createEmailPasswordSession(
      email: email,
      password: password,
    );
    return session.toMap();
  } on AppwriteException catch (error) {
    if (error.type == "user_session_already_exists") {
      account.deleteSession(sessionId: "current");
      return loginEmailAccount(email: email, password: password);
    } else {
      return {
        'error': true,
        'type': error.type,
        'message': error.message,
        'code': error.code,
      };
    }
  }
}