Skip to content

fix(gotrue)!: assert asyncStorage is provided for PKCE flow in the constructor - #1489

Open
gourabsingha1 wants to merge 7 commits into
supabase:mainfrom
gourabsingha1:fix/assert-async-storage-constructor-1446
Open

fix(gotrue)!: assert asyncStorage is provided for PKCE flow in the constructor#1489
gourabsingha1 wants to merge 7 commits into
supabase:mainfrom
gourabsingha1:fix/assert-async-storage-constructor-1446

Conversation

@gourabsingha1

@gourabsingha1 gourabsingha1 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Root cause
When flowType is AuthFlowType.pkce (the default) and no asyncStorage is provided, calling getOAuthSignInUrl() or getLinkIdentityUrl() fails late at call time. To provide a better developer experience and fail fast, the misconfiguration should be validated up front in the constructor.

Fix
Added an assert in the GoTrueClient constructor to validate that asyncStorage != null if flowType == AuthFlowType.pkce.

Tests

  • Added a unit test in gotrue/test/client_test.dart to verify that GoTrueClient throws an AssertionError if asyncStorage is missing when using PKCE flow.
  • Updated all test suites in gotrue and supabase packages to pass a mock storage or specify implicit flow type where no storage was configured.

Fixes #1446

Summary by CodeRabbit

  • New Features

    • Added in-memory storage for PKCE code verifiers.
    • Supabase clients now automatically use in-memory storage when PKCE is enabled without custom storage.
    • Added clear guidance for configuring persistent storage when verifiers must survive application restarts.
  • Bug Fixes

    • PKCE initialization now reports a descriptive error when required storage is unavailable.
  • Tests

    • Expanded coverage for PKCE flows, storage behavior, OAuth authentication, and client initialization.

@gourabsingha1
gourabsingha1 requested a review from a team as a code owner June 28, 2026 08:29
@Vinzent03

Copy link
Copy Markdown
Collaborator

As stated in your linked issue this is considered as a breaking change so won't plan this for main yet but later for v3 when we start actively working on it.

@spydon spydon changed the title fix(gotrue): assert asyncStorage is provided for PKCE flow in the constructor fix(gotrue)!: assert asyncStorage is provided for PKCE flow in the constructor Jun 29, 2026
@spydon
spydon changed the base branch from main to v3 June 29, 2026 14:12
@spydon spydon added the v3 label Jun 29, 2026
@spydon
spydon deleted the branch supabase:main July 7, 2026 07:42
@spydon spydon closed this Jul 7, 2026
@spydon spydon reopened this Jul 7, 2026
gourabsingha1 and others added 2 commits August 5, 2026 16:50
The constructor assertion trips every GoTrueClient and SupabaseClient built
without a pkce storage, including the suites main gained while this branch sat
on the old v3 base.
@spydon
spydon changed the base branch from v3 to main August 5, 2026 14:56
@spydon
spydon force-pushed the fix/assert-async-storage-constructor-1446 branch from 68a6a36 to 5297960 Compare August 5, 2026 15:00
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@spydon, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 11 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0058e92e-9a29-4fe8-bd79-205e6e42ae8f

📥 Commits

Reviewing files that changed from the base of the PR and between 41dcbfb and b494925.

📒 Files selected for processing (5)
  • packages/gotrue/lib/src/gotrue_client.dart
  • packages/gotrue/test/client_test.dart
  • packages/gotrue/test/src/gotrue_mfa_api_test.dart
  • packages/supabase/lib/src/supabase_client_options.dart
  • sdk-compliance.yaml
📝 Walkthrough

Walkthrough

Changes

The change adds MemoryGotrueAsyncStorage, validates required PKCE storage in GoTrueClient, updates test fixtures, and makes Supabase use in-memory storage by default for PKCE flows.

PKCE async storage

Layer / File(s) Summary
Memory-backed storage implementation
packages/gotrue/lib/src/types/gotrue_async_storage.dart, packages/gotrue/test/memory_async_storage_test.dart, packages/gotrue/test/utils.dart, packages/gotrue/example/main.dart, sdk-compliance.yaml
Adds the memory-backed storage implementation and tests its read, write, removal, overwrite, and instance-isolation behavior.
GoTrue constructor validation and fixtures
packages/gotrue/lib/src/gotrue_client.dart, packages/gotrue/test/client_test.dart, packages/gotrue/test/*, packages/gotrue/test/src/*
Requires async storage for PKCE flow, preserves storage-free implicit flow construction, and updates GoTrue test clients to use TestAsyncStorage.
Supabase PKCE fallback integration
packages/supabase/lib/src/supabase_client.dart, packages/supabase/lib/src/supabase_client_options.dart, packages/supabase/test/client_test.dart
Creates memory storage when the default PKCE flow has no configured storage and verifies that OAuth URLs include a PKCE code challenge.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SupabaseClient
  participant GoTrueClient
  participant MemoryGotrueAsyncStorage
  SupabaseClient->>MemoryGotrueAsyncStorage: Create fallback storage for PKCE
  SupabaseClient->>GoTrueClient: Initialize with PKCE and storage
  GoTrueClient->>MemoryGotrueAsyncStorage: Store PKCE verifier
  GoTrueClient-->>SupabaseClient: Return OAuth sign-in URL with code challenge
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the constructor assertion that requires asyncStorage for PKCE flow.
Linked Issues check ✅ Passed The PR implements the constructor assertion required by [#1446] and updates clients and tests to preserve PKCE behavior.
Out of Scope Changes check ✅ Passed The changes support the linked issue through implementation, storage fallback, documentation, and related test updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/gotrue/lib/src/gotrue_client.dart`:
- Around line 156-159: Replace the constructor assert in
packages/gotrue/lib/src/gotrue_client.dart:156-159 with runtime validation
enforcing that PKCE requires non-null asyncStorage, failing during construction.
Update the corresponding constructor test in
packages/gotrue/test/client_test.dart:869-894 to expect the runtime failure
rather than AssertionError.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 25a0956e-2ada-4718-8e25-8c26c6a81ebe

📥 Commits

Reviewing files that changed from the base of the PR and between 1862f74 and 5297960.

📒 Files selected for processing (18)
  • packages/gotrue/lib/src/gotrue_client.dart
  • packages/gotrue/test/admin_delete_user_test.dart
  • packages/gotrue/test/admin_test.dart
  • packages/gotrue/test/client_test.dart
  • packages/gotrue/test/header_isolation_test.dart
  • packages/gotrue/test/mfa_enroll_test.dart
  • packages/gotrue/test/src/gotrue_admin_custom_providers_api_test.dart
  • packages/gotrue/test/src/gotrue_admin_mfa_api_test.dart
  • packages/gotrue/test/src/gotrue_admin_oauth_api_test.dart
  • packages/gotrue/test/src/gotrue_mfa_api_test.dart
  • packages/gotrue/test/src/gotrue_oauth_api_test.dart
  • packages/supabase/test/client_test.dart
  • packages/supabase/test/mock_test.dart
  • packages/supabase/test/realtime_test.dart
  • packages/supabase/test/stream_filter_test.dart
  • packages/supabase/test/stream_integration_test.dart
  • packages/supabase/test/trace_propagation_test.dart
  • packages/supabase/test/utils.dart

Comment thread packages/gotrue/lib/src/gotrue_client.dart
The constructor assert makes asyncStorage mandatory for the pkce flow,
which is the default. Without a storage of its own the supabase package
would have made every SupabaseClient throw, so ship a
MemoryGotrueAsyncStorage in gotrue and use it when no storage is passed.
The gotrue tests keep the pkce flow and pass a storage instead of
switching to the implicit flow.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/gotrue/test/client_test.dart`:
- Around line 869-881: Replace the PKCE storage requirement assertion in the
GoTrueClient constructor with unconditional runtime validation that throws an
ArgumentError or StateError when PKCE is configured without asyncStorage. Update
the “Constructing a client without an asyncStorage” test to expect that runtime
exception while preserving the existing message assertion.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b273ef0f-b007-4cea-a877-831595787079

📥 Commits

Reviewing files that changed from the base of the PR and between 5297960 and 41dcbfb.

📒 Files selected for processing (11)
  • packages/gotrue/example/main.dart
  • packages/gotrue/lib/src/gotrue_client.dart
  • packages/gotrue/lib/src/types/gotrue_async_storage.dart
  • packages/gotrue/test/client_test.dart
  • packages/gotrue/test/header_isolation_test.dart
  • packages/gotrue/test/memory_async_storage_test.dart
  • packages/gotrue/test/utils.dart
  • packages/supabase/lib/src/supabase_client.dart
  • packages/supabase/lib/src/supabase_client_options.dart
  • packages/supabase/test/client_test.dart
  • sdk-compliance.yaml
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/gotrue/test/header_isolation_test.dart
  • packages/gotrue/lib/src/gotrue_client.dart

Comment thread packages/gotrue/test/client_test.dart
spydon added 2 commits August 5, 2026 17:41
isNotNull on a freshly constructed client can never fail, which DCM
flags as a misused test matcher.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves PKCE developer ergonomics in the Supabase Flutter SDK monorepo by validating (and/or supplying) the async storage required to persist PKCE code verifiers. It adds an in-memory GotrueAsyncStorage implementation and updates clients/tests to use it where appropriate.

Changes:

  • Added a GoTrueClient constructor assert for missing asyncStorage when flowType is PKCE, plus guidance in docs/examples.
  • Introduced MemoryGotrueAsyncStorage (in-memory PKCE verifier storage) and used it as a fallback in SupabaseClient when PKCE is enabled without a custom storage.
  • Updated/added tests to cover the new storage and to ensure PKCE flows work (or fail fast) under the new configuration rules.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
sdk-compliance.yaml Registers the new public MemoryGotrueAsyncStorage API symbols for compliance tracking.
packages/supabase/test/client_test.dart Adds a test asserting PKCE works without explicitly passing pkceAsyncStorage to SupabaseClient.
packages/supabase/lib/src/supabase_client.dart Falls back to MemoryGotrueAsyncStorage() when PKCE is used and no storage is provided.
packages/supabase/lib/src/supabase_client_options.dart Documents PKCE verifier storage behavior for AuthClientOptions.pkceAsyncStorage.
packages/gotrue/test/utils.dart Reworks TestAsyncStorage to reuse MemoryGotrueAsyncStorage.
packages/gotrue/test/src/gotrue_oauth_api_test.dart Supplies asyncStorage in OAuth API tests to satisfy PKCE requirements.
packages/gotrue/test/src/gotrue_mfa_api_test.dart Supplies asyncStorage in MFA API tests to satisfy PKCE requirements.
packages/gotrue/test/src/gotrue_admin_oauth_api_test.dart Supplies asyncStorage in admin OAuth API tests.
packages/gotrue/test/src/gotrue_admin_mfa_api_test.dart Supplies asyncStorage in admin MFA API tests.
packages/gotrue/test/src/gotrue_admin_custom_providers_api_test.dart Supplies asyncStorage in admin custom provider tests.
packages/gotrue/test/mfa_enroll_test.dart Supplies asyncStorage in MFA enroll test.
packages/gotrue/test/memory_async_storage_test.dart New unit tests covering MemoryGotrueAsyncStorage behavior.
packages/gotrue/test/header_isolation_test.dart Supplies asyncStorage in header isolation test.
packages/gotrue/test/client_test.dart Updates client tests for PKCE storage requirements and adds constructor-assert test.
packages/gotrue/test/admin_test.dart Supplies asyncStorage in admin test setup.
packages/gotrue/test/admin_delete_user_test.dart Supplies asyncStorage in delete-user admin test.
packages/gotrue/lib/src/types/gotrue_async_storage.dart Adds MemoryGotrueAsyncStorage implementation.
packages/gotrue/lib/src/gotrue_client.dart Adds constructor assert requiring asyncStorage for PKCE, with guidance in docs.
packages/gotrue/example/main.dart Updates example to pass MemoryGotrueAsyncStorage for PKCE flow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/gotrue/lib/src/gotrue_client.dart
Comment thread packages/supabase/lib/src/supabase_client_options.dart Outdated
spydon and others added 2 commits August 6, 2026 10:44
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@spydon
spydon requested a review from Vinzent03 August 6, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assert asyncStorage is provided for PKCE flow in the GoTrue client constructor

4 participants