Skip to content

refactor!: Refactor e-mail IDP provider to support Flutter client package - #4058

Merged
marcelomendoncasoares merged 9 commits into
serverpod:mainfrom
marcelomendoncasoares:refactor-email-client-interaction
Oct 16, 2025
Merged

marcelomendoncasoares merged 9 commits into
serverpod:mainfrom
marcelomendoncasoares:refactor-email-client-interaction

Conversation

@marcelomendoncasoares

Copy link
Copy Markdown
Collaborator

This PR enables #3644.

Account registration and Password reset now return a request ID

To allow a simple and secure verification process, we now return a request ID for both account registration and password reset requests. This request ID can be combined with the verification code sent via email to verify the request. As the ID is also sent via email, more advanced use cases such as magic links are still possible. For invalid requests, this ID will be a random UUID.

Hide account not found exceptions from the client

To enhance security, the system no longer throws any kind of "account not found" exception when a user tries to register an already existing email or reset the password for a non-existing email. Instead, it behaves as if the request was successful and throws a generic "unauthorized" error message when trying to complete the request. This change ensures that attackers cannot determine whether an email is registered in the system.

E-mail exception and reason refactor

Exceptions for email accounts have been renamed for better clarity and consistency, together with their reasons. Serialization has also been changed to use names instead of indexes, improving readability and maintainability. All exception reason enums now have a default value for future-proofing.

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

  • Major refactor on all email exception class names and their reasons. Will impact try-catch blocks that treat email exceptions on the server or client.
  • All email exception reason enum values now serialize by name instead of by index. Will break any code that serializes/deserializes or stores these values directly.
  • The exception of account not found is no longer thrown when trying to reset a password for an email that does not exist or register an email that exists. Will break client code that relies on these exceptions to show specific error messages.

@coderabbitai

coderabbitai Bot commented Oct 14, 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.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@marcelomendoncasoares
marcelomendoncasoares requested a review from a team October 14, 2025 03:54
@marcelomendoncasoares
marcelomendoncasoares marked this pull request as ready for review October 14, 2025 03:54

@SandPod SandPod 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.

Changes looks good and I like the cleanup of the exceptions.

Have a couple of comments.

@marcelomendoncasoares
marcelomendoncasoares force-pushed the refactor-email-client-interaction branch from 305a459 to bfd958a Compare October 16, 2025 03:18
@marcelomendoncasoares

Copy link
Copy Markdown
Collaborator Author

While working on this PR, we realized that the completePasswordReset method must be split in two: one for first verifying the reset password code and another to set the new password. This approach is standard practice and will improve both usability and security, ensuring that users have completed verification before being allowed to set a new password. @coderabbitai, can you create an issue for it?

@coderabbitai

coderabbitai Bot commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

# Create a GitHub issue for splitting the completePasswordReset method
gh issue create \
  --title "Split completePasswordReset method into verification and password setting steps" \
  --body "## Description

While working on PR #4058, it was identified that the \`completePasswordReset\` method should be split into two separate methods:

1. One method for verifying the reset password code
2. Another method for setting the new password

## Rationale

This approach is standard practice and will improve both usability and security by ensuring that users have completed verification before being allowed to set a new password.

## References

- Related PR: https://github.com/serverpod/serverpod/pull/4058
- Original discussion: https://github.com/serverpod/serverpod/pull/4058#discussion_r1947768449

Requested by: @marcelomendoncasoares" \
  --assignee marcelomendoncasoares

echo "Issue created successfully"

Length of output: 77


@marcelomendoncasoares, I've created issue #4067 to track the splitting of the completePasswordReset method into two separate steps. The issue has been assigned to you and includes references back to this PR and the discussion.

    /)/)
   (^.^)
   (")_(") ✓

@SandPod SandPod changed the title refactor: Refactor e-mail IDP provider to support Flutter client package refactor!: Refactor e-mail IDP provider to support Flutter client package Oct 16, 2025

@SandPod SandPod 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.

Looks good now, had a last couple of questions and suggestions.

@SandPod SandPod 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.

LGTM! 👍

@marcelomendoncasoares
marcelomendoncasoares merged commit dac42c3 into serverpod:main Oct 16, 2025
@marcelomendoncasoares
marcelomendoncasoares deleted the refactor-email-client-interaction branch October 16, 2025 19:01
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 16, 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.

2 participants