isSignedIn method

Future<bool> isSignedIn()

Whether the user has a usable session.

Returns true when the access token exists AND either (a) its stored expiry is still in the future, (b) no expiry is stored (legacy install, no way to tell), or (c) the expiry is in the past but a refresh token is available so getAccessToken() can auto-recover. Expired access tokens with no refresh token are reported as signed-out — the UI can then prompt for a fresh sign-in instead of showing a stuck "signed in but every call fails" state.

Implementation

Future<bool> isSignedIn() async {
  final token = await _storage.read(key: _accessTokenKey);
  if (token == null || token.isEmpty) return false;

  final expiryStr = await _storage.read(key: _expiryKey);
  if (expiryStr == null) return true;

  final expiry = DateTime.tryParse(expiryStr);
  if (expiry == null || expiry.isAfter(DateTime.now())) return true;

  final refreshToken = await _storage.read(key: _refreshTokenKey);
  return refreshToken != null && refreshToken.isNotEmpty;
}