Skip to content

docs(examples): add authentication example covering all sign in methods#1627

Merged
spydon merged 7 commits into
mainfrom
lukasklingsbo/sdk-1059-1064-example-authentication
Jul 22, 2026
Merged

docs(examples): add authentication example covering all sign in methods#1627
spydon merged 7 commits into
mainfrom
lukasklingsbo/sdk-1059-1064-example-authentication

Conversation

@spydon

@spydon spydon commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

What

Adds a single example app under examples/authentication that demonstrates every supabase_flutter sign in method except passkeys (which already have their own passkeys example). Pick a method with the chips at the top; once signed in you land on an account screen that manages MFA and can upgrade an anonymous user to a permanent account.

Covers these parity example tickets:

  • SDK-1059 Email & password: signUp, signInWithPassword, and a full password reset (resetPasswordForEmail, then verifyOTP with OtpType.recovery and updateUser)
  • SDK-1060 Passwordless: signInWithOtp(email:) + verifyOTP(type: OtpType.email)
  • SDK-1061 OAuth social: signInWithOAuth (Google, GitHub, Apple), including deep-link redirect
  • SDK-1062 Phone / SMS: signInWithOtp(phone:) + verifyOTP(type: OtpType.sms)
  • SDK-1063 Anonymous: signInAnonymously, then updateUser to upgrade to a permanent account
  • SDK-1064 MFA (TOTP): auth.mfa.enroll, challengeAndVerify, listFactors, unenroll

How

  • All supabase.auth.* calls live in lib/auth_repository.dart, kept separate from the UI so the flows are easy to read and to drive from an integration test. The UI just calls the repository and rebuilds from onAuthStateChange.
  • Follows the structure, naming and comment style of the database_crud example.
  • The shared Supabase config in examples/supabase/config.toml enables anonymous sign in, phone auth (with a local test OTP so no SMS provider is needed), TOTP MFA, and the local mail server. Custom magic_link and recovery email templates include the one-time code so the email OTP and reset flows can be completed by typing it. [inbucket] was renamed to the current [local_smtp] section along the way. The example stores no data of its own, so it needs no migration or seed.

Testing

Booted the shared local stack and verified against the API that email/password sign up, email OTP (captured by the local mail server), the full password reset loop, phone OTP with the test number, anonymous sign in and its upgrade to a permanent account all work. dart format and flutter analyze are clean. End-to-end integration tests follow in stacked PR #1628; writing them surfaced two display/rebuild bugs that are fixed here.

Summary by CodeRabbit

  • New Features

    • Added a Flutter authentication example covering password, magic-link/email OTP, phone OTP, OAuth, anonymous sign-in, password recovery, and TOTP MFA.
    • Added native deep-link handling for email and OAuth flows.
    • Added local authentication testing support, including email capture and fixed SMS OTP configuration.
    • Added magic-link and password-recovery email templates displaying verification codes and links.
  • Documentation

    • Added setup, configuration, usage, and local testing instructions for the authentication example.
    • Updated the examples feature table.

@spydon
spydon requested a review from a team as a code owner July 21, 2026 10:10
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This pull request adds a Flutter authentication example to the workspace. It provides password, email and phone OTP, OAuth, anonymous account linking, sign-out, and TOTP MFA flows through an authentication repository and UI, with local Supabase configuration, email templates, SMTP capture, web bootstrap files, and documentation.

Changes

Authentication example

Layer / File(s) Summary
Example foundation
examples/authentication/..., pubspec.yaml
Adds the Flutter package, workspace registration, lint configuration, web host page, ignored generated artifacts, and AuthMethod model.
Authentication repository
examples/authentication/lib/auth_repository.dart
Centralizes password, recovery, email and phone OTP, OAuth, anonymous linking, sign-out, and TOTP MFA calls.
Authentication application flows
examples/authentication/lib/main.dart
Adds Supabase initialization, auth-state-driven screens, authentication forms, anonymous upgrades, sign-out, MFA enrollment, factor removal, and snackbar feedback.
Local authentication configuration
examples/supabase/config.toml, examples/supabase/templates/*
Enables anonymous auth, email and phone OTP testing, TOTP MFA, local SMTP capture, and magic-link and recovery templates.
Example documentation
examples/README.md, examples/authentication/README.md
Documents the example, configuration, startup commands, and local testing procedures.

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

Sequence Diagram(s)

sequenceDiagram
  participant HomePage
  participant AuthRepository
  participant SupabaseAuth
  participant LocalSMTP
  HomePage->>AuthRepository: submit authentication action
  AuthRepository->>SupabaseAuth: execute selected auth operation
  SupabaseAuth-->>LocalSMTP: capture OTP or recovery email
  SupabaseAuth-->>AuthRepository: return auth response
  AuthRepository-->>HomePage: update authentication view
Loading

Suggested reviewers: tr00d

🚥 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 matches the main change: adding an authentication example that covers the sign-in methods.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch lukasklingsbo/sdk-1059-1064-example-authentication

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 `@examples/authentication/lib/auth_repository.dart`:
- Around line 42-44: Update AuthRepository methods sendPasswordReset and
sendEmailOtp to accept and forward the appropriate redirect parameters
(redirectTo/emailRedirectTo) to the Supabase auth calls, preserving existing
email behavior. Also update _OAuthButtons._signIn to provide the configured
redirectTo when invoking signInWithOAuth so native OAuth flows return to the
app.
🪄 Autofix (Beta)

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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e9744760-d435-4658-80c1-a5c010b5545d

📥 Commits

Reviewing files that changed from the base of the PR and between 0931f0a and 6cc021b.

📒 Files selected for processing (11)
  • examples/README.md
  • examples/authentication/.gitignore
  • examples/authentication/README.md
  • examples/authentication/analysis_options.yaml
  • examples/authentication/lib/auth_repository.dart
  • examples/authentication/lib/main.dart
  • examples/authentication/lib/models.dart
  • examples/authentication/pubspec.yaml
  • examples/authentication/web/index.html
  • examples/supabase/config.toml
  • pubspec.yaml

Comment thread examples/authentication/lib/auth_repository.dart Outdated
spydon added 5 commits July 21, 2026 15:19
Add a single example under examples/authentication that demonstrates every
supabase_flutter sign in method except passkeys: email & password, magic link
and email OTP, phone (SMS) OTP, OAuth social, anonymous sign in with account
upgrade, and TOTP multi-factor authentication.

All auth calls live in a thin AuthRepository so the flows are easy to read and
to drive from an integration test. The shared Supabase config enables anonymous
sign in, phone auth with a local test OTP, TOTP MFA and the local mail server.

Covers SDK-1059, SDK-1060, SDK-1061, SDK-1062, SDK-1063 and SDK-1064.
The default magic-link email only carries a link, so the authentication
example's email OTP flow could not be completed by typing a code. Add a custom
magic_link template that also shows {{ .Token }}, matching what the example's UI
and README describe.
…n example

The example only sent the reset email. Add the recovery step: enter the code
from the email and a new password to finish the reset (verifyOTP with
OtpType.recovery, then updateUser). Add a recovery email template that includes
the code, matching the magic-link one.
Two fixes in the authentication example found while writing its tests:

- A phone-only user comes back with an empty email string, so the account
  title fell back to nothing instead of the phone number.
- The signed-in view was a const instance, which the framework skips
  rebuilding, so upgrading an anonymous account did not refresh the screen.
  Pass the user in so it rebuilds on every auth change.
Pass a redirectTo/emailRedirectTo through the OAuth, magic link/email OTP and
password reset calls so native builds return to the app after the provider or
email link, using a deep link that is null on web (site URL) and registered in
the shared config's additional_redirect_urls.
@spydon
spydon force-pushed the lukasklingsbo/sdk-1059-1064-example-authentication branch from bf794de to e6a6196 Compare July 21, 2026 13:22
spydon added a commit that referenced this pull request Jul 22, 2026
## What

Adds a repo-level `.coderabbit.yaml` that disables CodeRabbit's failing
commit status:

```yaml
reviews:
  commit_status: true
  fail_commit_status: false
```

## Why

Open PRs are currently showing a red `CodeRabbit` check with the reason
**"Review rate limited"** (e.g. #1630, #1629, #1627), even though
nothing is actually wrong with the change. A completed review shows
`pass` (e.g. #1626).

- `commit_status: true` keeps the useful passing check for completed
reviews.
- `fail_commit_status: false` stops CodeRabbit from setting a `failure`
status when it can't review (which is what the rate-limit case
triggers).

Committing the config overrides CodeRabbit's cloud/org defaults.

## Note

If a rate-limited PR still goes red after this lands, the rate-limit
failure path ignores this flag and the only remaining lever is
`commit_status: false` (disables the check entirely, losing the green
pass too).
…9-1064-example-authentication

# Conflicts:
#	examples/README.md

@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 `@examples/authentication/README.md`:
- Line 3: Update the user-facing descriptions in the authentication README to
consistently hyphenate “sign-in,” including the overview and the referenced
email, phone, and anonymous sign-in descriptions.
🪄 Autofix (Beta)

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

Run ID: 967427ce-7168-4dad-8bed-0761bf2dda52

📥 Commits

Reviewing files that changed from the base of the PR and between bf794de and 149b6cf.

📒 Files selected for processing (13)
  • examples/README.md
  • examples/authentication/.gitignore
  • examples/authentication/README.md
  • examples/authentication/analysis_options.yaml
  • examples/authentication/lib/auth_repository.dart
  • examples/authentication/lib/main.dart
  • examples/authentication/lib/models.dart
  • examples/authentication/pubspec.yaml
  • examples/authentication/web/index.html
  • examples/supabase/config.toml
  • examples/supabase/templates/magic_link.html
  • examples/supabase/templates/recovery.html
  • pubspec.yaml
🚧 Files skipped from review as they are similar to previous changes (9)
  • examples/authentication/web/index.html
  • examples/authentication/pubspec.yaml
  • pubspec.yaml
  • examples/authentication/.gitignore
  • examples/authentication/lib/models.dart
  • examples/README.md
  • examples/supabase/config.toml
  • examples/authentication/lib/auth_repository.dart
  • examples/authentication/lib/main.dart

Comment thread examples/authentication/README.md
…9-1064-example-authentication

# Conflicts:
#	examples/README.md
@spydon
spydon merged commit 47ceaaf into main Jul 22, 2026
37 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-1059-1064-example-authentication branch July 22, 2026 14:27
spydon added a commit that referenced this pull request Jul 23, 2026
…1628)

Stacked on #1627.

## What

Adds
`examples/authentication/integration_test/authentication_test.dart`, an
end-to-end suite that drives the authentication app widgets against the
local Supabase stack, mirroring the `database_crud` and `passkeys`
example tests. One sign in method per test:

- **Email & password**: sign up, sign out, a failed sign in, then a
successful one.
- **Password reset**: request a reset, read the recovery code back from
the local mail server, set a new password, then sign in with it.
- **Passwordless email OTP**: send the code, read it back from the mail
server, enter it and verify.
- **Phone SMS OTP**: send to the configured test number and verify with
the fixed test code, so no SMS provider is needed.
- **Anonymous**: continue as a guest, then upgrade the same user to a
permanent account with an email and password.
- **MFA (TOTP)**: enroll a factor, compute the current code from the
returned secret (RFC 6238, in-test), verify it, then remove the factor.
- **OAuth**: assert the provider buttons render. The redirect itself
hands off to an external browser and deep link that cannot be automated
headlessly, so it is exercised manually per the README.

Adds `crypto` and `http` as dev dependencies, used only by the test to
compute the TOTP code and to read OTP emails from the local mail server.

## Web vs native targets

The password reset and email OTP tests read the code back from the local
mail server over HTTP. A browser blocks that cross-origin request, so
those two are skipped on web (via `kIsWeb`) and run on native targets
such as `-d macos`, where there is no such restriction.

## Verification

Ran the suite headlessly against the running local stack (Chrome +
chromedriver): **7 passed, 2 skipped, 0 failed**. The five widget-driven
flows that don't touch the mail server pass end to end (email &
password, phone SMS OTP, anonymous + upgrade, MFA, OAuth buttons), and
the two mail-server tests are skipped on web. Both skipped flows were
additionally validated end to end against the backend API (email
delivery, the six-digit-code extraction, recovery verify, and setting a
new password), and they run on `-d macos`.

Writing the tests surfaced two real bugs in the example, fixed in the
base PR #1627: a phone-only user has an empty email string (so the
account title showed nothing), and the signed-in view was a `const`
instance the framework skipped rebuilding (so an anonymous upgrade did
not refresh the screen).

`dart format` and `flutter analyze` are clean.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added end-to-end integration tests covering password, passwordless
email OTP, phone sign-in, anonymous upgrade, MFA (TOTP add/remove), and
OAuth button rendering.
* **Bug Fixes**
* Improved test coverage around recovery and OTP behaviors, including
appropriate web-vs-native skipping.
* **Documentation**
* Expanded the authentication example guide with clearer local test
instructions, including which flows are automated vs manually exercised
and the exact `flutter test` command.
* **Chores**
* Updated the authentication example dependencies to enable local OTP
retrieval and MFA TOTP generation during tests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants