Skip to content

Commit a25993c

Browse files
authored
fix: Add error messages for when the session or expiresAt was missing while making API requests. (#976)
* fix: add error message for when the session is missing * let request fire with empty session
1 parent 6323f9f commit a25993c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/supabase/lib/src/auth_http_client.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ class AuthHttpClient extends BaseClient {
1414
try {
1515
await _auth.refreshSession();
1616
} catch (error) {
17-
// Failed to refresh the token.
18-
final isExpiredWithoutMargin = DateTime.now().isAfter(
19-
DateTime.fromMillisecondsSinceEpoch(
20-
_auth.currentSession!.expiresAt! * 1000));
21-
if (isExpiredWithoutMargin) {
22-
// Throw the error instead of making an API request with an expired token.
23-
rethrow;
17+
final expiresAt = _auth.currentSession?.expiresAt;
18+
if (expiresAt != null) {
19+
// Failed to refresh the token.
20+
final isExpiredWithoutMargin = DateTime.now()
21+
.isAfter(DateTime.fromMillisecondsSinceEpoch(expiresAt * 1000));
22+
if (isExpiredWithoutMargin) {
23+
// Throw the error instead of making an API request with an expired token.
24+
rethrow;
25+
}
2426
}
2527
}
2628
}

0 commit comments

Comments
 (0)