Repository navigation
feat(auth2): Add hook for when user is migrated in serverpod_auth_migration - #3728
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 WalkthroughWalkthroughA new general configuration class, Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test Suite
participant AuthMigrationEmail as AuthMigrationEmail
participant Config as AuthMigrationConfig
participant Hook as userMigrationHook
Test->>AuthMigrationEmail: migrateOnLogin/migrateWithoutPassword(...)
AuthMigrationEmail->>AuthMigrationEmail: _migrateUserIfNeeded(...)
AuthMigrationEmail-->>AuthMigrationEmail: (migratedUser, didCreate)
alt didCreate is true and userMigrationHook is set
AuthMigrationEmail->>Hook: userMigrationHook(session, oldUserId, newAuthUserId, transaction)
end
AuthMigrationEmail-->>Test: Result (migratedUser)
Assessment against linked issues
Possibly related PRs
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
exaby73
left a comment
There was a problem hiding this comment.
Small nit on tests but otherwise LGTM
Adds a hook to the
serverpod_auth_migrationpackage which is called once for each user migration (when going fromUserInfotoAuthUser).Apps that store data with a relation to the
UserInfoshould use this callback (in atransaction) to migrate that user's data to be reachable via the newAuthUserID (as the mapping between the old and new user is bound to disappear once the migration is complete and the old tables are dropped).Initially the idea was to return a
MigrationResult?from themigrateOnLoginandmigrateWithoutPasswordmethod respectively, but that API proved hard to use in practice (because one would have to wrap them in one's own function to not repeat oneself and pass in a transaction, but since the signatures are slightly different (the first one needs apasswordparameter) that could not be written succinctly (without resorting to fallbacks like having an optional password parameter).The current approach is also more robust in that the custom migration can not be forgotten later on when adding new auth providers etc.
(The downside with "function configurations" is always the initial setup, and that the code/flow can not be read linearly, as the place they call out to is not immediately visible.)
Closes #3709
Summary by CodeRabbit
New Features
Bug Fixes
Tests