Repository navigation
Description
Currently, the way serverpod_auth_migration is designed, driven by some challenges with the legacy data1, a developer would have to keep a dependency on it to support eventual migrations, of e.g. the email passwords, in their endpoints.
But since the migration package has a dependency on the legacy serverpod_auth and all its counterpart packages from the new serverpod_auth_* packages, the migration part drags on for a long time, as it's only "done" when all account details have been fully migrated (some currently requiring a login into that account, to e.g. get the old password), or when the developer decides that "enough" account details have been migrated to drop the old tables and thus any chance of further imports.
Thus we should split the migration and legacy support into 2 distinct packages and steps.
The goal is to have the migration finished as fast as possible, and then be able to completely drop serverpod_auth from the codebase (also transitively!) so the developer can be sure that they are not relying on any old code anymore (and for example the legacy auth endpoints disappear, as do the legacy tables from the original auth package).
Packages
server_auth_migration
Should only support the actual migration of the data, from serverpod_auth to the new packages, and a new "legacy support" package for data that can not be fully migrated.
To run the migration as a one-off (by default) we can discard the current configuration approach and instead just provide a single function (which runs a single transaction) to run the migration. This function would take the configuration (whether to import the profile for example) and a callback for any custom migrations to be done.
Dependencies:
serverpod_authserverpod_auth_legacy_supportserverpod_auth_userserverpod_auth_sessionserverpod_auth_profile(might not be used, depending on the configuration)serverpod_auth_email, … (Apple, Firebase, Google account packages)
Tables:
MigratedUserfor the mapping of legacy to new user IDs- Only used during the migration to keep track of migrated users, in case the developer uses smaller batch sizes
- If the code fully changes to migrate an entire user "at once" (which the current
serverpod_auth_migrationdoes not do), then it would even suffice to just store the old migrated user IDs here and don't need to worry about the mapping (a developer could still store such a mapping in a way that makes sense for them via the user migration hook callback)
serverpod_auth_legacy_support
Supports ongoing look-ups / migrations for legacy user data that can not yet be migrated to the new system.
For example:
- Legacy sessions will be stored here indefinitely and not be migrated to the new
serverpod_auth_session, as there is no way to tell the client about the new session key (and we don't want to support the legacy format in the new system)- We could add a "last used at" column there (with corse resolution), so developers could easily identify unused legacy sessions and thus find out when these are no longer practically useful
- Email account hashes in the old format. This package would have a copy of the old hashing algorithm to check the password on
loginendpoint calls. If it's correct, the new endpoint will set the incoming password for the email account in the new email account package. - Since external user identifiers don't store their provider yet, we have to retain them here in an unstructured way. New social provider endpoints could then look up an incoming ID in this module and see which user it belongs to, and then store it properly in their module.
For the email passwords and social logins, any "used" row should be deleted, so that the diminishing reliance on the legacy data can be tracked over time.
Dependencies:
- TBD
- Maybe this should depend on the new endpoint packages (e.g.
serverpod_auth_emailto give developers a pre-configured base endpoint, and e.g. an "augmented"authenticationHandler)- The drawback is that this might pull in an unused provider (e.g. Firebase), but really only creates an empty table for those.
- On the plus side this would make the configuration and usage much simpler. Without a dependency we'd have to somehow share interfaces between the packages in a "dependency free" way and the developer would have to hook them up correctly.
Tables:
LegacySession(String hash, Uuid AuthUserId)LegacyEmailPassword(String hash, Uuid emailAccountID)LegacyExternalUserIdentifier(String userIdentifier, Uuid AuthUserId)
Process
(This assumes no backwards compatibility requirements for the legacy login/registration endpoints, but does retain compatibility with logged-in clients and their sessions.)
- Add the desired new auth packages to the application
- Remove any direct dependencies on
serverpod_auth - Add the migration package, configure the custom migration callback to replace legacy user IDs with the new ones in the application's own entities
- Add legacy support where desired (e.g. session handler, email login endpoint, etc.)
- Deploy. Wait for the migration code run to completion
- Remove
serverpod_auth_migrationpackage from the codebase, ensure that no more indirect dependency onserverpod_authexists either - Deploy again, dropping the unused tables
The dependency on the serverpod_auth_legacy_support has to be kept for a while then though, as the migration for the email password and social logins can only take place at the speed at which users log in with those methods. Likewise, the sessions will only be migrated when users re-login or switch devices. But since that package and its data are minimal and focused, that is still a huge improvement over keeping the entire migration package with its dependency on the legacy auth.
Footnotes
-
E.g. the password storage changed and is configurable for the legacy email accounts, and thus we can not copy the hashes over without supporting all previous options as well. Further the social login "user IDs" (externally set) lack any information about which provider they came from, and thus can not be migrated into the individual packages. ↩
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone 🚀
Activity
christerswahn commentedon Jul 3, 2025
Sounds good!
Regarding dependencies, it would be valuable to not create unused database tables - this would be surprising to users that are for example not using Firebase provider. Maybe worth while to look if it can be both simple to configure and use, and not have that dependency being required?
Should there be a followup path where the Serverpod user removes the
serverpod_auth_legacy_supportpackage and its tables, after having determined remaining table rows (if any) are not worth keeping?Also, for users not migrating from the old auth module, the DB should be free from legacy stuff, are they able to avoid dependency on the
serverpod_auth_legacy_supportpackage and legacy DB tables?tp commentedon Jul 3, 2025
I think that would be really tricky, like (currently) only with the "shared interface" (but no direct dependencies) approach alluded to above.
The same goes for example with the new profile package. Currently the migration allows configuring whether to copy the data over, and in case the developer opts out they still have that empty table.
We could of course instead switch this around, say a callback
onProfileMigrationto configure, where the developer could plug in the matching from from theserverpod_auth_profilepackage.But such configurations do add up quickly (if every "target" package/provider requires an extra configuration step).
On the other hand the empty table (and especially the needlessly noisy migrations) are not great either, but at least there is less chance to just "forget" some connection.
Yes, this is basically "step 8" in the free text. I'll make sure to clarify this in the docs for this feature.
Yes, users just using a new auth package (like
serverpod_auth_email) will not see any of the legacy support classes or tables. The legacy support package might depend on the new ones (in order to pre-configured that for the developer), but not vice-versa.