Skip to content

feat(gotrue): convert OAuthProvider from enum to class for custom provider support#1339

Open
grdsdev wants to merge 2 commits intomainfrom
guilherme/sdk-794-oauth-provider-custom-string
Open

feat(gotrue): convert OAuthProvider from enum to class for custom provider support#1339
grdsdev wants to merge 2 commits intomainfrom
guilherme/sdk-794-oauth-provider-custom-string

Conversation

@grdsdev
Copy link
Copy Markdown
Contributor

@grdsdev grdsdev commented Mar 27, 2026

Summary

  • Converts OAuthProvider from a plain Dart enum to a final class, enabling arbitrary provider strings at runtime
  • Adds a regression test covering construction, URL generation, equality, and values enumeration
  • All existing call sites (OAuthProvider.google, .snakeCase, == OAuthProvider.google) continue to work unchanged

Root Cause

OAuthProvider was declared as a Dart enum. The Supabase docs show:

await supabase.auth.signInWithOAuth(OAuthProvider('custom:my-provider'));

But calling a generative enum constructor at runtime is illegal in Dart, producing:

Generative enum constructors can only be used to create an enum constant.

Fixes: #1337

Changes

  • packages/gotrue/lib/src/types/types.dart: Replace enum OAuthProvider with final class OAuthProvider. Built-in providers become static const fields storing pre-converted snake_case wire names (linkedinOidc'linkedin_oidc', slackOidc'slack_oidc'). Adds snakeCase getter, ==/hashCode, and static const List<OAuthProvider> values.
  • packages/gotrue/test/custom_oauth_provider_test.dart: New regression test (6 cases).

Backward Compatibility

Usage Status
OAuthProvider.google / all static constants ✅ Unchanged
provider == OAuthProvider.google ✅ Works via == override
provider.snakeCase ✅ Works via class getter
OAuthProvider.values ✅ Preserved as static const list
switch (provider) exhaustiveness ⚠️ No longer compiler-enforced — users need a default case
linkedinOidc.name / slackOidc.name ⚠️ Changes from 'linkedinOidc''linkedin_oidc' (internal enum name, not the API wire value)

Testing

dart test test/custom_oauth_provider_test.dart
+6: All tests passed!
dart analyze packages/gotrue/lib/ packages/supabase_flutter/lib/
No issues found!

Linear

SDK-794


🤖 Generated with Claude Code

…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>
Copilot AI review requested due to automatic review settings March 27, 2026 08:58
@github-actions github-actions bot added the auth This issue or pull request is related to authentication label Mar 27, 2026
@grdsdev grdsdev requested a review from a team March 27, 2026 09:01
Copy link
Copy Markdown

Copilot AI left a comment

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 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 OAuthProvider with a final class OAuthProvider that accepts arbitrary provider strings and preserves existing static constants.
  • Adds value-based equality/hashCode and a values list 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>
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.

Generic OAuth Signin not working

2 participants