syncAuthSessionRefresh function

void syncAuthSessionRefresh({
  1. required String? issuedAtValue,
  2. required Duration? updateAge,
  3. required void writeIssuedAt(
    1. DateTime issuedAtUtc
    ),
  4. DateTime? now,
  5. void touchSession()?,
})

Applies issued-at refresh semantics through write and touch callbacks.

Returns without invoking a callback when updateAge is null. Initialization and refresh write the current UTC time; refresh also invokes touchSession when supplied.

Implementation

void syncAuthSessionRefresh({
  required String? issuedAtValue,
  required Duration? updateAge,
  required void Function(DateTime issuedAtUtc) writeIssuedAt,
  DateTime? now,
  void Function()? touchSession,
}) {
  final age = updateAge;
  if (age == null) {
    return;
  }

  final current = (now ?? DateTime.now()).toUtc();
  final action = authSessionRefreshAction(
    issuedAtValue: issuedAtValue,
    updateAge: age,
    now: current,
  );

  switch (action) {
    case AuthSessionRefreshAction.initialize:
      writeIssuedAt(current);
      return;
    case AuthSessionRefreshAction.refresh:
      writeIssuedAt(current);
      touchSession?.call();
      return;
    case AuthSessionRefreshAction.keep:
      return;
  }
}