login static method

Future<Map<String, dynamic>> login(
  1. String email,
  2. String password, {
  3. String? throttleKey,
})

Implementation

static Future<Map<String, dynamic>> login(
  String email,
  String password, {
  String? throttleKey,
}) async {
  _validateLoginThrottle(email, throttleKey: throttleKey);

  final qb = QueryBuilder(table: _config.table);
  final user =
      await qb.where(_config.emailColumn, '=', email).limit(1).first();

  if (user == null) {
    _registerLoginFailure(email, throttleKey: throttleKey);
    throw AuthException(message: 'Invalid email or password');
  }

  final hashedPassword = user[_config.passwordColumn] as String;
  final isMatch = Hashing().verify(password, hashedPassword);

  if (!isMatch) {
    _registerLoginFailure(email, throttleKey: throttleKey);
    throw AuthException(message: 'Invalid email or password');
  }

  if (_config.requireEmailVerification && user['email_verified_at'] == null) {
    throw AuthException(message: 'Email verification required.');
  }

  _registerLoginSuccess(email, throttleKey: throttleKey);
  final cleanUser = _sanitizeUserData(user);
  _ensureJwtSecretConfigured();
  final token = _issueAccessToken(cleanUser);

  return {
    'user': cleanUser,
    'token': token,
  };
}