signInUser static method

Future<AuthKey> signInUser(
  1. Session session,
  2. int userId,
  3. String method, {
  4. Set<Scope> scopes = const {},
})

Signs in an user to the server. The user should have been authenticated before signing them in. Send the AuthKey.id and key to the client and use that to authenticate in future calls. In most situations you should use one of the auth providers instead of this method.

Implementation

static Future<AuthKey> signInUser(
  Session session,
  int userId,
  String method, {
  Set<Scope> scopes = const {},
}) async {
  var signInSalt = session.passwords['authKeySalt'] ?? defaultAuthKeySalt;

  var key = generateRandomString();
  var hash = hashString(signInSalt, key);

  var scopeNames = <String>[];
  for (var scope in scopes) {
    if (scope.name != null) scopeNames.add(scope.name!);
  }

  var authKey = AuthKey(
    userId: userId,
    hash: hash,
    key: key,
    scopeNames: scopeNames,
    method: method,
  );

  session.updateAuthenticated(AuthenticationInfo(userId, scopes));
  var result = await AuthKey.db.insertRow(session, authKey);
  return result.copyWith(key: key);
}