destroySession static method

Future<void> destroySession(
  1. Session session, {
  2. required UuidValue authSessionId,
  3. Transaction? transaction,
})

Removes the specified session and thus signs out its user on its device.

This does not affect the user's sessions on other devices.

If the session does not exist, this method will have no effect.

Implementation

static Future<void> destroySession(
  final Session session, {
  required final UuidValue authSessionId,
  final Transaction? transaction,
}) async {
  // Delete the user session for the current device
  final authSession = (await AuthSession.db.deleteWhere(
    session,
    where: (final row) => row.id.equals(authSessionId),
    transaction: transaction,
  ))
      .firstOrNull;

  if (authSession == null) {
    return;
  }

  // Notify the client about the revoked authentication for the specific
  // user session
  await session.messages.authenticationRevoked(
    authSession.authUserId.uuid,
    RevokedAuthenticationAuthId(authId: authSessionId.toString()),
  );
}