Skip to content

docs(gotrue): require onError handler in onAuthStateChange#1355

Merged
grdsdev merged 1 commit intomainfrom
docs/on-auth-state-change-error-handler
Apr 20, 2026
Merged

docs(gotrue): require onError handler in onAuthStateChange#1355
grdsdev merged 1 commit intomainfrom
docs/on-auth-state-change-error-handler

Conversation

@grdsdev
Copy link
Copy Markdown
Contributor

@grdsdev grdsdev commented Apr 16, 2026

Summary

  • Updates onAuthStateChange doc comment in GoTrueClient with an explicit warning that onError is required, plus a corrected usage example
  • Fixes the example app which was missing onError and would crash when the device had no connectivity

Background

Closes #1281.

Network errors (e.g. a token refresh while offline) are emitted as stream errors on onAuthStateChange. Without an onError handler, Dart rethrows them as unhandled zone exceptions, crashing the app. The SDK's own internal listener in supabase_auth.dart already handles this correctly — the gap was in documentation and the example app.

A companion PR in the reference docs repo updates all code examples on supabase.com: supabase/supabase#44946

Changes

packages/gotrue/lib/src/gotrue_client.dart

  • Rewrote the onAuthStateChange doc comment to warn that onError is required
  • Updated the inline code example to show correct usage with onError

packages/supabase_flutter/example/lib/main.dart

  • Added onError handler to the .listen() call that was missing it

Test plan

  • Confirm example app no longer crashes when device goes offline during a token refresh
  • Confirm doc comment renders correctly in IDE tooling

🤖 Generated with Claude Code

Network errors (e.g. offline token refresh) are emitted as stream errors
on onAuthStateChange. Without an onError handler, Dart rethrows them as
unhandled zone exceptions and crashes the app.

- Update onAuthStateChange doc comment in GoTrueClient with a clear
  warning and a corrected usage example that includes onError
- Fix the supabase_flutter example app which was missing onError and
  would crash when the device had no connectivity

Fixes #1281

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot added the auth This issue or pull request is related to authentication label Apr 16, 2026
@grdsdev grdsdev merged commit 74bb172 into main Apr 20, 2026
16 checks passed
@grdsdev grdsdev deleted the docs/on-auth-state-change-error-handler branch April 20, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth This issue or pull request is related to authentication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fatal exception when offline

2 participants