refreshToken method

Future<void> refreshToken(
  1. Session session, {
  2. required AppleAccount appleAccount,
  3. required void onExpiredUserAuthentication(
    1. UuidValue authUserId
    ),
})

Refreshes the Apple appleAccount's refresh token to ensure it is still valid.

If the token has been revoked, the onExpiredUserAuthentication callback is invoked with the associated auth user's ID.

Implementation

Future<void> refreshToken(
  final Session session, {
  required final AppleAccount appleAccount,
  required final void Function(UuidValue authUserId)
  onExpiredUserAuthentication,
}) async {
  await AppleAccount.db.updateRow(
    session,
    appleAccount.copyWith(lastRefreshedAt: clock.now()),
  );

  try {
    await _signInWithApple.validateRefreshToken(
      appleAccount.refreshToken,
      useBundleIdentifier:
          appleAccount.refreshTokenRequestedWithBundleIdentifier,
    );
  } on RevokedTokenException catch (_) {
    onExpiredUserAuthentication(appleAccount.authUserId);
  }
}