Skip to content

refactor!: Split complete password reset step in two for Email IDP. - #4159

Merged
SandPod merged 15 commits into
serverpod:mainfrom
SandPod:4067-split-complete-password-reset
Nov 6, 2025
Merged

SandPod merged 15 commits into
serverpod:mainfrom
SandPod:4067-split-complete-password-reset

Conversation

@SandPod

@SandPod SandPod commented Nov 5, 2025 •

Copy link
Copy Markdown
Contributor

This PR refactors the password reset process by splitting the final step into two separate actions:

  • Validation of the verification code
  • Setting the new password

This separation enables independent validation for each stage and introduces flexibility for future MFA integration.

New flow

Screenshot 2025-11-05 at 10 40 58

Once the validation code has been verified, a reset token code is generated that can be submitted together with the password. The separation allows the possibility of injecting user-enforced MFA steps.

The validation code is only returned once from the verify method, meaning the user will need to store it if additional steps are added, and then submit it once all their validation have passed.

Validation change

I moved the expired check to happen before we validate the security code and check if the request has been verified. That was to ensure that we remove expired requests. The user still needs to have the unique ID of the request in order to get the expired message, which is a UUID and should be almost impossible to brute force.

Closes: #4067

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Breaking changes

Yes, this changes the flow of a password reset. But the changes are related to a non released package.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added password reset code verification endpoint to the email authentication flow.
    • Implemented two-step password reset process: verify reset code before completing password change.
  • Bug Fixes

    • Enhanced error handling with new exception types for password reset scenarios.

@coderabbitai

coderabbitai Bot commented Nov 5, 2025 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This PR implements a two-step password reset flow by splitting completePasswordReset into separate verification and password-setting steps. A new verifyPasswordResetCode method validates reset codes and generates set-password tokens, while completePasswordReset now uses the verified token. Changes include new exceptions, configuration options, data model updates, and comprehensive test coverage.

Changes

Cohort / File(s) Summary
Core business logic
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.dart, ...email_idp_password_reset_util.dart
Added verifyPasswordResetCode method to validate reset codes, generate and store set-password tokens, and return SetPasswordCredentials containing reset request ID and verification code. Delegates to password reset utilities with transaction support.
Configuration and code generation
...email_idp_config.dart, ...util/default_code_generators.dart
Added setPasswordTokenGenerator field to EmailIDPConfig with default defaultSetPasswordTokenGenerator. Introduced new defaultSetPasswordTokenGenerator() function generating UUID v4 tokens.
Exception definitions
...email_idp_server_exceptions.dart, ...email_idp_utils.dart
Added EmailPasswordResetVerificationCodeAlreadyUsedException and EmailPasswordResetSetPasswordTokenNotFoundException exception classes. Updated exception-to-reason mapping to treat new exceptions as invalid reset reasons.
API endpoint
...endpoints/email_idp_base_endpoint.dart
Added public verifyPasswordResetCode endpoint method delegating to EmailIDP.verifyPasswordResetCode. Returns SetPasswordCredentials with documentation.
Data model
...models/email_account_password_reset_request.spy.yaml
Added setPasswordChallenge: SecretChallenge? optional relation field (cascade on delete) to store verified password reset token.
Test utilities
tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
Added verifyPasswordResetCode methods to _EmailAccountEndpoint and _PasswordImportingEmailAccountEndpoint with request/response serialization. Updated _UserProfileEndpoint.setUserImage parameter type.
Module unit tests
modules/new_serverpod_auth/.../test/email/email_idp/*, ...test/email/utils/email_idp_password_reset_util/*
Added comprehensive test suite email_idp_verify_password_reset_code_test.dart and verify_password_reset_code_test.dart covering verification success, invalid/expired codes, duplicate usage, rate limiting. Updated existing tests to use two-step verification flow before password reset completion.
Integration tests
tests/serverpod_new_auth_test/.../test/integration/email_account_endpoint_test.dart, ...email_account_migration_test.dart
Updated password reset flows to call verifyPasswordResetCode before finishPasswordReset, capturing returned credentials for subsequent password setting. Adjusted error expectations and test descriptions to reflect new two-step flow.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Endpoint as EmailIDPBaseEndpoint
    participant EmailIDP
    participant PasswordResetUtil
    participant DB as Database

    rect rgb(200, 220, 255)
    Note over Client,DB: Step 1: Verify Password Reset Code
    Client->>Endpoint: verifyPasswordResetCode(requestId, code)
    Endpoint->>EmailIDP: verifyPasswordResetCode()
    EmailIDP->>PasswordResetUtil: verifyPasswordResetCode()
    PasswordResetUtil->>DB: Load reset request & challenge
    PasswordResetUtil->>DB: Validate: not expired, not used
    PasswordResetUtil->>PasswordResetUtil: Generate setPasswordToken
    PasswordResetUtil->>DB: Store token as setPasswordChallenge
    PasswordResetUtil->>DB: Mark request as verified
    PasswordResetUtil-->>EmailIDP: Return SetPasswordCredentials
    EmailIDP-->>Endpoint: Return SetPasswordCredentials
    Endpoint-->>Client: {passwordResetRequestId, verificationCode}
    end

    rect rgb(220, 255, 220)
    Note over Client,DB: Step 2: Complete Password Reset (existing flow)
    Client->>Endpoint: finishPasswordReset(requestId, setVerificationCode, newPassword)
    Endpoint->>EmailIDP: completePasswordReset()
    EmailIDP->>PasswordResetUtil: completePasswordReset()
    PasswordResetUtil->>DB: Load reset request & setPasswordChallenge
    PasswordResetUtil->>DB: Validate setPasswordChallenge exists
    PasswordResetUtil->>DB: Update password, cleanup challenges
    PasswordResetUtil-->>EmailIDP: Success
    EmailIDP-->>Endpoint: Success
    Endpoint-->>Client: Success
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Areas requiring extra attention:

  • Transaction handling in verifyPasswordResetCode: Verify proper transaction wrapping, rollback semantics, and exception handling across the new verification flow in EmailIDPPasswordResetUtil.verifyPasswordResetCode.
  • Token lifecycle and usage state: Validate setPasswordChallenge storage, the new isVerificationCodeUsed getter logic, and state transitions between verification and password setting steps in EmailAccountPasswordResetRequest.
  • Exception mapping and error paths: Review newly introduced exceptions (EmailPasswordResetVerificationCodeAlreadyUsedException, EmailPasswordResetSetPasswordTokenNotFoundException) and their handling in email_idp_utils.dart to ensure proper reason mapping.
  • Test coverage comprehensiveness: Verify that new test suites (email_idp_verify_password_reset_code_test.dart, verify_password_reset_code_test.dart) adequately cover edge cases (expiration, rate limiting, duplicate usage, non-existent requests) and that updated existing tests correctly reflect the new two-step flow throughout both module and integration tests.
  • Configuration wiring: Confirm setPasswordTokenGenerator is correctly propagated from EmailIDPConfig through EmailIDPPasswordResetUtilsConfig.fromEmailIDPConfig() factory and used consistently in token generation.

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary refactoring: splitting the complete password reset step into two separate actions for the Email IDP provider.
Description check ✅ Passed The PR description fully addresses the requirements: explains what is being changed (split password reset into validation and password setting), why (enables flexibility and future MFA), lists the linked issue (#4067), and documents breaking changes.
Linked Issues check ✅ Passed The PR successfully implements the requirements from issue #4067: splits completePasswordReset into separate verification and password-setting methods, ensures verification before password setting, and improves security through staged validation.
Out of Scope Changes check ✅ Passed All changes are in scope and directly support the password reset refactoring objective. The modifications to test files, endpoint implementations, and utility methods all align with splitting the password reset process into verification and password-setting stages.

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

@SandPod
SandPod force-pushed the 4067-split-complete-password-reset branch from 649b880 to 8dfcaea Compare November 5, 2025 09:38
@SandPod SandPod changed the title 4067 split complete password reset refactor!: Split complete password reset step in two for Email IDP. Nov 5, 2025
@SandPod
SandPod force-pushed the 4067-split-complete-password-reset branch from 8dfcaea to 4996609 Compare November 5, 2025 09:50
@SandPod
SandPod force-pushed the 4067-split-complete-password-reset branch 2 times, most recently from 99560c3 to 35ed6b3 Compare November 5, 2025 10:32
@SandPod
SandPod force-pushed the 4067-split-complete-password-reset branch from 35ed6b3 to 8985d0f Compare November 5, 2025 10:40
@SandPod

SandPod commented Nov 5, 2025

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 5, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 58b2a11 and 8985d0f.

⛔ Files ignored due to path filters (44)
  • examples/auth/auth_client/lib/src/protocol/client.dart is excluded by !**/lib/src/protocol/**
  • examples/auth/auth_client/lib/src/protocol/protocol.dart is excluded by !**/lib/src/protocol/**
  • examples/auth/auth_server/lib/src/generated/endpoints.dart is excluded by !**/generated/**
  • examples/auth/auth_server/lib/src/generated/protocol.dart is excluded by !**/generated/**
  • examples/auth/auth_server/lib/src/generated/protocol.yaml is excluded by !**/generated/**
  • examples/auth/auth_server/migrations/20251105092806197/definition.json is excluded by !**/migrations/**
  • examples/auth/auth_server/migrations/20251105092806197/definition.sql is excluded by !**/migrations/**
  • examples/auth/auth_server/migrations/20251105092806197/definition_project.json is excluded by !**/migrations/**
  • examples/auth/auth_server/migrations/20251105092806197/migration.json is excluded by !**/migrations/**
  • examples/auth/auth_server/migrations/20251105092806197/migration.sql is excluded by !**/migrations/**
  • examples/auth/auth_server/migrations/migration_registry.txt is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_bridge/serverpod_auth_bridge_server/migrations/20251105092831755/definition.json is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_bridge/serverpod_auth_bridge_server/migrations/20251105092831755/definition.sql is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_bridge/serverpod_auth_bridge_server/migrations/20251105092831755/definition_project.json is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_bridge/serverpod_auth_bridge_server/migrations/20251105092831755/migration.json is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_bridge/serverpod_auth_bridge_server/migrations/20251105092831755/migration.sql is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_bridge/serverpod_auth_bridge_server/migrations/migration_registry.txt is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_client/lib/src/protocol/client.dart is excluded by !**/lib/src/protocol/**
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_client/lib/src/protocol/protocol.dart is excluded by !**/lib/src/protocol/**
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/generated/protocol.dart is excluded by !**/generated/**
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/generated/providers/email/models/email_account_password_reset_request.dart is excluded by !**/generated/**
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/migrations/20251105092721874/definition.json is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/migrations/20251105092721874/definition.sql is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/migrations/20251105092721874/definition_project.json is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/migrations/20251105092721874/migration.json is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/migrations/20251105092721874/migration.sql is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/migrations/migration_registry.txt is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/migrations/20251105092847663/definition.json is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/migrations/20251105092847663/definition.sql is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/migrations/20251105092847663/definition_project.json is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/migrations/20251105092847663/migration.json is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/migrations/20251105092847663/migration.sql is excluded by !**/migrations/**
  • modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/migrations/migration_registry.txt is excluded by !**/migrations/**
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_client/lib/src/protocol/client.dart is excluded by !**/lib/src/protocol/**
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_client/lib/src/protocol/protocol.dart is excluded by !**/lib/src/protocol/**
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/lib/src/generated/endpoints.dart is excluded by !**/generated/**
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/lib/src/generated/protocol.dart is excluded by !**/generated/**
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/lib/src/generated/protocol.yaml is excluded by !**/generated/**
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/migrations/20251105092903219/definition.json is excluded by !**/migrations/**
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/migrations/20251105092903219/definition.sql is excluded by !**/migrations/**
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/migrations/20251105092903219/definition_project.json is excluded by !**/migrations/**
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/migrations/20251105092903219/migration.json is excluded by !**/migrations/**
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/migrations/20251105092903219/migration.sql is excluded by !**/migrations/**
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/migrations/migration_registry.txt is excluded by !**/migrations/**
📒 Files selected for processing (18)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.dart (2 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_config.dart (3 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_server_exceptions.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_utils.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/utils/email_idp_password_reset_util.dart (8 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/endpoints/email_idp_base_endpoint.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/models/email_account_password_reset_request.spy.yaml (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/util/default_code_generators.dart (2 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart (19 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_start_password_reset_test.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_verify_password_reset_code_test.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/complete_password_reset_test.dart (15 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/delete_password_reset_requests_test.dart (9 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/start_password_reset_test.dart (3 hunks)
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/verify_password_reset_code_test.dart (1 hunks)
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart (7 hunks)
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart (4 hunks)
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart (4 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.dart

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.dart: Format all Dart code using dart format . before committing
Code must pass Dart analyzer in strict mode (util/run_tests_analyze or melos lint_strict)
Use descriptive variable and function names

Files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/endpoints/email_idp_base_endpoint.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/verify_password_reset_code_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_utils.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_verify_password_reset_code_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_start_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_server_exceptions.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/util/default_code_generators.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/start_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/complete_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_config.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/delete_password_reset_requests_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/utils/email_idp_password_reset_util.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart
**/lib/**/*.dart

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Remove unnecessary comments from production code

Files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/endpoints/email_idp_base_endpoint.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_utils.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_server_exceptions.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/util/default_code_generators.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_config.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/utils/email_idp_password_reset_util.dart
**/*_test.dart

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*_test.dart: Write test descriptions using the Given/When/Then pattern
Organize tests with passing/success cases first, group related cases using group(), then follow with error cases

Files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/verify_password_reset_code_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_verify_password_reset_code_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_start_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/start_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/complete_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/delete_password_reset_requests_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart
🧠 Learnings (19)
📚 Learning: 2025-11-03T15:40:41.827Z
Learnt from: SandPod
Repo: serverpod/serverpod PR: 4144
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart:0-0
Timestamp: 2025-11-03T15:40:41.827Z
Learning: In Serverpod authentication IDP endpoint files (modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server), endpoint base classes should import `serverpod_auth_idp_server/core.dart` to access the Session type, rather than importing `package:serverpod_auth_core_server/session.dart` directly. This pattern is consistently used in Apple, Email, and Google endpoint files.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/endpoints/email_idp_base_endpoint.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/verify_password_reset_code_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_utils.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_verify_password_reset_code_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_start_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_server_exceptions.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/util/default_code_generators.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/start_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/complete_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_config.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/delete_password_reset_requests_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/utils/email_idp_password_reset_util.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart
📚 Learning: 2025-08-26T13:22:33.125Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3829
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/business/passkey_accounts.dart:0-0
Timestamp: 2025-08-26T13:22:33.125Z
Learning: The passkeys_server Dart library evolved from version 0.3.0 to 0.4.0, adding required parameters to verifyRegistration and verifyLogin methods for complete WebAuthn security validation including challenge, clientDataJSON, and attestationObject verification.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/endpoints/email_idp_base_endpoint.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/verify_password_reset_code_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_utils.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_verify_password_reset_code_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_start_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_server_exceptions.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/util/default_code_generators.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/start_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/complete_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_config.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/delete_password_reset_requests_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/utils/email_idp_password_reset_util.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart
📚 Learning: 2025-09-17T16:09:20.868Z
Learnt from: nielsenko
Repo: serverpod/serverpod PR: 3980
File: packages/serverpod/lib/src/web_server/web_server.dart:102-115
Timestamp: 2025-09-17T16:09:20.868Z
Learning: In Serverpod's web server authentication handling (packages/serverpod/lib/src/web_server/web_server.dart), query parameter authentication fallback (`authenticationKey ??= queryParameters['auth']`) is intentionally maintained for legacy compatibility reasons, even though it has security implications regarding credential leakage.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/endpoints/email_idp_base_endpoint.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_utils.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_start_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/util/default_code_generators.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_config.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/utils/email_idp_password_reset_util.dart
📚 Learning: 2025-10-15T11:44:29.873Z
Learnt from: CR
Repo: serverpod/serverpod PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T11:44:29.873Z
Learning: Applies to **/*_test.dart : Organize tests with passing/success cases first, group related cases using group(), then follow with error cases

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/verify_password_reset_code_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_verify_password_reset_code_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/start_password_reset_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart
📚 Learning: 2025-08-25T19:46:58.073Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3917
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/analysis_options.yaml:3-6
Timestamp: 2025-08-25T19:46:58.073Z
Learning: In Serverpod, test tool paths like `test/integration/test_tools/serverpod_test_tools.dart` are configured per project in the "generator.yaml" file and managed by a generator system, so they don't need to be updated manually across all files at once.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/verify_password_reset_code_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_verify_password_reset_code_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/util/default_code_generators.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/start_password_reset_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/delete_password_reset_requests_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart
📚 Learning: 2025-06-18T14:49:11.263Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3672
File: tests/serverpod_test_server/test_integration/test_tools/test_session_builder_test.dart:10-30
Timestamp: 2025-06-18T14:49:11.263Z
Learning: In Serverpod test files, tp prefers using nullable late variables for AuthenticationInfo in tests (e.g., `late AuthenticationInfo? authenticationInfo;`) rather than non-nullable ones to avoid using `!` operators and to get clearer error messages when authentication setup fails. This provides better diagnostics when `session.authenticated` returns null.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/verify_password_reset_code_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_verify_password_reset_code_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_start_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/start_password_reset_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/complete_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/delete_password_reset_requests_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart
📚 Learning: 2025-11-04T12:09:52.649Z
Learnt from: marcelomendoncasoares
Repo: serverpod/serverpod PR: 4150
File: examples/auth/auth_flutter/lib/widgets/profile_info.dart:23-30
Timestamp: 2025-11-04T12:09:52.649Z
Learning: In Serverpod example and testing projects (e.g., examples/auth/auth_flutter), prefer letting errors bubble up naturally rather than handling them gracefully with catchError or try-catch blocks. This helps developers see what went wrong during development and testing.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/verify_password_reset_code_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_utils.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_verify_password_reset_code_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_server_exceptions.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/complete_password_reset_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart
📚 Learning: 2025-06-17T11:38:13.087Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3666
File: modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_accounts_admin.dart:130-143
Timestamp: 2025-06-17T11:38:13.087Z
Learning: In serverpod_auth_email_account EmailAccountsAdmin, tp prefers relying on database unique constraint exceptions over application-level pre-insert checks for email uniqueness, especially in contexts with longer-running transactions where TOCTOU issues could still occur.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_utils.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_server_exceptions.dart
📚 Learning: 2025-06-16T12:08:40.049Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3651
File: modules/new_serverpod_auth/serverpod_auth_email/serverpod_auth_email_server/lib/src/endpoints/email_account_endpoint.dart:37-49
Timestamp: 2025-06-16T12:08:40.049Z
Learning: In serverpod_auth_email_server, the startRegistration method intentionally does not propagate EmailAccountRequestResult failures to the caller to prevent information leakage about account existence. Only server-side logging is performed for admin monitoring purposes.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_utils.dart
📚 Learning: 2025-06-17T11:39:51.491Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3666
File: modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_accounts_admin.dart:157-163
Timestamp: 2025-06-17T11:39:51.491Z
Learning: In `EmailAccountsAdmin` class methods, it's appropriate to throw specific errors like `EmailAccountNotFound` when email accounts don't exist, since this is admin-only functionality marked as `internal`. However, in non-admin/public-facing contexts, avoid exposing whether email accounts exist to prevent account enumeration attacks - use generic error messages instead.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_utils.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_server_exceptions.dart
📚 Learning: 2025-07-02T16:09:27.702Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3747
File: tests/serverpod_new_auth_test/serverpod_new_auth_test_server/pubspec.yaml:37-38
Timestamp: 2025-07-02T16:09:27.702Z
Learning: In Serverpod migration testing, it's appropriate for test servers like serverpod_new_auth_test_server to include dependencies on both legacy packages (e.g., serverpod_auth_server) and new modular packages to enable comprehensive testing of migration paths from old to new authentication systems.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_verify_password_reset_code_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart
📚 Learning: 2025-06-16T12:07:26.018Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3651
File: modules/new_serverpod_auth/serverpod_auth_email_account/serverpod_auth_email_account_server/lib/src/business/email_accounts.dart:35-39
Timestamp: 2025-06-16T12:07:26.018Z
Learning: The `withServerpod` test helper runs tests within a transaction, which may require adapting database queries to accept transaction parameters for proper snapshot consistency during testing.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/complete_password_reset_test.dart
📚 Learning: 2025-11-02T17:36:02.137Z
Learnt from: SandPod
Repo: serverpod/serverpod PR: 4131
File: tests/serverpod_cli_e2e_test/test/generate_with_directory_test.dart:67-70
Timestamp: 2025-11-02T17:36:02.137Z
Learning: In Serverpod test files, use `assert` for setup preconditions in `setUp()` or `setUpAll()` blocks (e.g., verifying project creation succeeded) to distinguish setup failures from test assertion failures. Reserve `expect` for actual test assertions within test cases.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/complete_password_reset_test.dart
📚 Learning: 2025-06-20T12:49:16.373Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3666
File: modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/test/integration/auth_migration_email_test.dart:0-0
Timestamp: 2025-06-20T12:49:16.373Z
Learning: In test files, when testing that an async method completes without error (especially when the test name/description mentions "completes without error"), use the pattern `await expectLater(asyncMethodCall(), completes)` instead of just `await asyncMethodCall()`. This makes the test intention explicit and provides better test failure messages. However, don't apply this pattern to setup calls or when testing side effects rather than completion behavior. For tests that check both completion and side effects, consider splitting into separate tests or prioritize the primary assertion.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_start_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/delete_password_reset_requests_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart
📚 Learning: 2025-06-20T12:49:16.373Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3666
File: modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/test/integration/auth_migration_email_test.dart:0-0
Timestamp: 2025-06-20T12:49:16.373Z
Learning: In test files, when testing that an async method completes without error (especially when the test name/description mentions "completes without error"), use the pattern `await expectLater(asyncMethodCall(), completes)` instead of just `await asyncMethodCall()`. This makes the test intention explicit and provides better test failure messages. However, don't apply this pattern to setup calls or when testing side effects rather than completion behavior.

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_start_password_reset_test.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/delete_password_reset_requests_test.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart
📚 Learning: 2025-07-02T16:07:50.947Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3747
File: modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/lib/src/business/migrating_email_endpoint_base.dart:4-4
Timestamp: 2025-07-02T16:07:50.947Z
Learning: In Serverpod, tp prefers importing the full package (e.g., 'package:serverpod_auth_migration_server/serverpod_auth_migration_server.dart') as a baseline rather than using smaller local imports, even within the same package where it might be considered a "self-import".

Applied to files:

  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/util/default_code_generators.dart
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
  • modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_config.dart
📚 Learning: 2025-06-19T11:00:17.085Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3651
File: tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart:1-1
Timestamp: 2025-06-19T11:00:17.085Z
Learning: In Serverpod applications, methods that rely on public asset storage (like setUserImage/removeUserImage) should be tested in E2E tests rather than withServerpod integration tests, as they require a full server environment with asset storage infrastructure to properly test image upload/download functionality.

Applied to files:

  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
📚 Learning: 2025-07-24T13:01:52.743Z
Learnt from: tp
Repo: serverpod/serverpod PR: 3826
File: modules/new_serverpod_auth/serverpod_auth_apple/serverpod_auth_apple_client/lib/serverpod_auth_apple_client.dart:1-1
Timestamp: 2025-07-24T13:01:52.743Z
Learning: High-level serverpod_auth_* packages (like serverpod_auth_apple_client) should re-export their serverpod_auth_* dependencies so that consumers only need to import the high-level package and don't get warnings about importing from non-dependency packages. The re-exports should hide conflicting elements like 'Caller' and 'Protocol' to avoid naming conflicts. This pattern prevents users from needing to directly depend on multiple internal implementation packages.

Applied to files:

  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
📚 Learning: 2025-07-01T13:01:27.054Z
Learnt from: exaby73
Repo: serverpod/serverpod PR: 3741
File: modules/serverpod_auth/serverpod_auth_server/analysis_options.yaml:14-16
Timestamp: 2025-07-01T13:01:27.054Z
Learning: In Serverpod, first-party packages like serverpod_auth_server can appropriately use blanket `invalid_use_of_internal_member: ignore` directives in their analysis_options.yaml since they use internal Database methods internally without exposing them in their public APIs to end users.

Applied to files:

  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Migration e2e tests (3.35.2)
  • GitHub Check: Migration e2e tests (3.29.0)
  • GitHub Check: dart analyze downgrade (3.29.0, windows-latest)
🔇 Additional comments (15)
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_finish_password_reset_test.dart (3)

24-24: LGTM! Two-step flow correctly implemented.

The test properly implements the new verification flow: first obtaining the initial verification code, then calling verifyPasswordResetCode to get the set-password token, which is stored for use in subsequent finishPasswordReset calls. The variable naming clearly distinguishes between the initial verification code and the set-password token.

Also applies to: 30-30, 56-63


174-182: Verify the timing semantics of the two-step flow.

The verification call occurs within the withClock block (before expiration), but the finishPasswordReset calls occur after the clock advances. This means the set-password token is generated and remains valid even though the original reset request has expired.

Please confirm this is the intended behavior: should the set-password token have its own expiration independent of the original reset request? If so, consider adding a test that verifies the set-password token can expire independently.


211-231: LGTM! Expired check priority correctly implemented.

The test correctly expects expired reason even when providing an invalid verification code. This aligns with the PR objective that expired checks now occur before verification-state checks, ensuring expired requests are always identified first.

modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_utils.dart (1)

110-112: LGTM! Exception mapping is correct.

The two new exceptions are appropriately mapped to the invalid reason, consistent with similar error cases like EmailPasswordResetInvalidVerificationCodeException and EmailPasswordResetRequestNotFoundException.

modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp.dart (1)

11-11: LGTM! Method implementation follows established patterns.

The new verifyPasswordResetCode method correctly follows the same architectural pattern as other methods in the class: transaction management, exception wrapping, and delegation to utility functions. The implementation is consistent and correct.

Also applies to: 244-265

modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/util/default_code_generators.dart (1)

3-3: LGTM! Token generator implementation is appropriate.

Using UUID v4 for set-password tokens is a good choice, providing sufficient entropy and unpredictability for one-time security tokens. The implementation follows the same pattern as the existing verification code generator.

Also applies to: 22-25

modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/models/email_account_password_reset_request.spy.yaml (1)

16-18: LGTM! Data model change supports two-step flow.

The optional setPasswordChallenge field correctly supports the new two-step password reset flow, allowing storage of the challenge after verification completes. The cascade delete ensures proper cleanup of related data.

modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_server_exceptions.dart (1)

84-91: LGTM! Exception classes are well-defined.

The two new exception classes are appropriately scoped, well-documented, and follow the existing exception hierarchy pattern. The names clearly convey the error conditions they represent.

modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/business/email_idp_config.dart (1)

3-3: LGTM! Configuration properly extended.

The new setPasswordTokenGenerator field is well-documented and properly integrated with a sensible default. The import consolidation to default_code_generators is a good organizational improvement.

Also applies to: 77-80, 149-149

tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_migration_test.dart (1)

197-212: LGTM! Integration tests correctly updated.

All four test cases consistently implement the new two-step password reset flow. The tests properly verify that the migration functionality works correctly with the refactored password reset process, maintaining the same security guarantees (e.g., legacy password clearing).

Also applies to: 225-238, 278-291, 315-328

modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/email_idp/email_idp_start_password_reset_test.dart (1)

60-72: Solid verification coverage.

Nice job asserting the flow now yields SetPasswordCredentials, keeping the test aligned with the two-step reset contract.

modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/start_password_reset_test.dart (1)

401-417: Thanks for refreshing the multi-request scenario.

Verifying the second request and capturing the credentials check ensures the new handshake is exercised end to end.

modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/email/endpoints/email_idp_base_endpoint.dart (1)

122-145: Documentation clarifies the split flow.

The new endpoint plus guidance about multi-step overrides makes the contract obvious for integrators.

modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/delete_password_reset_requests_test.dart (1)

56-109: Great guardrails around cleanup.

These verification-focused expectations validate that request pruning behaves correctly without regressing the new token flow.

modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/test/email/utils/email_idp_password_reset_util/complete_password_reset_test.dart (1)

183-248: Excellent negative-path coverage.

Catching the set-password-token-not-found case locks in the requirement to call verifyPasswordResetCode first.

@SandPod
SandPod marked this pull request as ready for review November 5, 2025 16:20
@SandPod
SandPod requested a review from a team November 5, 2025 16:21

@marcelomendoncasoares marcelomendoncasoares left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just two comments regarding:

  • Name verificationCode for the set password token parameter.
  • Possible leakage of existing accounts when throwing expired for wrong verification code.

@SandPod
SandPod force-pushed the 4067-split-complete-password-reset branch from 7238383 to 52ad805 Compare November 6, 2025 11:02

@marcelomendoncasoares marcelomendoncasoares left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🚀

@SandPod
SandPod merged commit b55586c into serverpod:main Nov 6, 2025
@SandPod
SandPod deleted the 4067-split-complete-password-reset branch November 6, 2025 12:50
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split completePasswordReset method into verification and password setting steps

2 participants