Repository navigation
Description
Describe the bug
We had yesterday during testing a incident where one of our devices went into an state where it was switching be tween authenticated and unauthenticated.
Looking at the logs we have seen that it tried in very short time to refresh it's out token but got a 400 error response with the message: "Invalid Refresh Token: Already Used".
It also never emitted a unauthenticated state instead that error ended up in the onError handler.
Is this the expected behaviour and should we handle all errors as unauthenticated or should the on auth listener a unauthenticated state?
For more context this is the code that handles the auth state changes:
_sessionSubscription =
Supabase.instance.client.auth.onAuthStateChange.listen(
(data) async {
final user = data.session?.user;
if (user != null && user.id != '' && user.role == 'authenticated') {
await _handleAuthenticatedEvent(user);
} else {
_handleUnauthenticatedEvent();
}
},
onError: (error, stackTrace) async {
emit(
state.copyWith(
status: AutoAuthenticationStatus.streamFail,
error: error.toString(),
),
);
super.onError(error, stackTrace);
_sessionSubscription?.cancel();
await Future.delayed(const Duration(seconds: 1));
Supabase.instance.client.auth.refreshSession();
_startStream();
},
);We changed it to now handle the error as unauthenticated.
To Reproduce
Steps to reproduce the behavior:
- Invalidate the refresh token
- check the logs for refresh retry
Expected behavior
Would expect to emit unauthenticated state to get returned but are not sure if that is expected.
Screenshots
I don't have a screenshot but happy to share the logs if that is helpful.
Version (please complete the following information):
├── supabase_flutter 1.10.22
│ ├── supabase 1.11.9
│ │ ├── functions_client 1.3.2
│ │ ├── gotrue 1.12.4
│ │ ├── postgrest 1.5.1
│ │ ├── realtime_client 1.3.0
│ │ ├── storage_client 1.5.3
Additional context
Add any other context about the problem here.
Activity