feat(gotrue): convert OAuthProvider from enum to class for custom provider support#1339
Open
feat(gotrue): convert OAuthProvider from enum to class for custom provider support#1339
Conversation
…vider support
OAuthProvider was a plain Dart enum, making it impossible to use custom/generic
OAuth providers at runtime. The docs show `OAuthProvider('custom:my-provider')` but
this produced a compile-time error: "Generative enum constructors can only be used
to create an enum constant."
OAuthProvider is now a `final class` with a `const OAuthProvider(String name)`
constructor so arbitrary provider strings work, while all existing static constants
(OAuthProvider.google, .github, etc.) remain unchanged.
Changes:
- Replace `enum OAuthProvider` with `final class OAuthProvider` in types.dart
- Built-in providers stored with pre-converted snake_case wire names (linkedin_oidc,
slack_oidc) so `snakeCase` getter just returns `name` — no runtime conversion needed
- Add `static const List<OAuthProvider> values` for enumeration compatibility
- Override `==` / `hashCode` for value-based equality
- Add regression tests covering construction, URL generation, equality, and values list
Acceptance Criteria:
- [x] OAuthProvider('custom:my-provider') compiles and works
- [x] All built-in providers (OAuthProvider.google, etc.) unchanged
- [x] provider.snakeCase returns correct wire format for all providers
- [x] dart analyze reports no issues in gotrue or supabase_flutter
Linear: SDK-794
Closes: #1337
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the GoTrue Dart API to support runtime-defined OAuth providers by replacing OAuthProvider from a Dart enum to a final class, aligning the SDK with documented usage for custom providers.
Changes:
- Replaces
enum OAuthProviderwith afinal class OAuthProviderthat accepts arbitrary provider strings and preserves existing static constants. - Adds value-based equality/hashCode and a
valueslist for built-in provider enumeration. - Introduces a regression test validating custom provider construction, URL generation, equality, and
values.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/gotrue/lib/src/types/types.dart | Converts OAuthProvider to a class with const built-ins, values, and value-based semantics. |
| packages/gotrue/test/custom_oauth_provider_test.dart | Adds regression tests for custom provider support and compatibility behaviors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…exhaustiveness test
- Mark `snakeCase` as `@Deprecated('Use name instead.')` with updated doc
comment clarifying it returns the wire value as-is with no case conversion
- Replace magic `hasLength(22)` with a source-derived count so the test
automatically catches any new static const provider missing from `values`
- Fix URL assertion in custom provider test to use parsed query parameters
instead of raw URL string matching
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OAuthProviderfrom a plain Dartenumto afinal class, enabling arbitrary provider strings at runtimeOAuthProvider.google,.snakeCase,== OAuthProvider.google) continue to work unchangedRoot Cause
OAuthProviderwas declared as a Dartenum. The Supabase docs show:But calling a generative enum constructor at runtime is illegal in Dart, producing:
Fixes: #1337
Changes
packages/gotrue/lib/src/types/types.dart: Replaceenum OAuthProviderwithfinal class OAuthProvider. Built-in providers becomestatic constfields storing pre-converted snake_case wire names (linkedinOidc→'linkedin_oidc',slackOidc→'slack_oidc'). AddssnakeCasegetter,==/hashCode, andstatic const List<OAuthProvider> values.packages/gotrue/test/custom_oauth_provider_test.dart: New regression test (6 cases).Backward Compatibility
OAuthProvider.google/ all static constantsprovider == OAuthProvider.google==overrideprovider.snakeCaseOAuthProvider.valuesswitch (provider)exhaustivenessdefaultcaselinkedinOidc.name/slackOidc.name'linkedinOidc'→'linkedin_oidc'(internal enum name, not the API wire value)Testing
Linear
SDK-794
🤖 Generated with Claude Code