build(user,phone-auth)!: upgrade SuperTokens node to v16 - #1120
Draft
KabinKhandThakuri wants to merge 22 commits into
Draft
build(user,phone-auth)!: upgrade SuperTokens node to v16#1120KabinKhandThakuri wants to merge 22 commits into
KabinKhandThakuri wants to merge 22 commits into
Conversation
…nClaim for multitenancy support
KabinKhandThakuri
marked this pull request as draft
June 17, 2026 11:02
Wire the SQL migration into runMigrations, map AuthUser.thirdParty, and update docs.
Harden profile-claim fail-closed behavior, gate ST v6 migration by tableSchema, and add HTTP email/phoneNumber aliases for older clients.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR upgrades
@prefabs.tech/fastify-userand@prefabs.tech/fastify-phone-authfrom supertokens-node 14 → 16, introduces an auth abstraction layer so application handlers no longer depend directly on SuperTokens APIs, and ships a re-runnable SuperTokens Core v6 multitenancy migration that runs automatically on plugin register.Highlights
supertokens-nodeis now>=16.0.0(was>=14.1.4)packages/user/src/auth/) — handlers talk toauth/getAuth()instead of SuperTokens recipes directly; SuperTokens is an optional, pluggable providerAuthUseris the thin auth-provider DTO (id,email, optionalthirdParty, …), notSupertokensUser & User. Userequest.user/Userfor DB fields (disabled,roles,profile, …).request.sessionis typed asAuthSessiontenantId(default"public")emails[],phoneNumbers[]); signup flag iscreatedNewRecipeUserclients+thirdPartyId); factories loaded fromsupertokens-node/lib/build/recipe/thirdparty/providersresetPasswordUsingTokenreplaced withconsumePasswordResetTokensmsDelivery.override.sendSms(dev mode only logs; no deprecatedcreateAndSendCustomTextMessage)supertokens-core-v6.sqlis applied automatically inrunMigrations(same transaction as users/invitations). Statements useIF EXISTS/IF NOT EXISTS/ON CONFLICT(includingDROP CONSTRAINT IF EXISTS) so re-runs are safeWhat changed
1. Auth abstraction (
@prefabs.tech/fastify-user)Handlers, GraphQL resolvers, Mercurius auth, and middlewares now go through a provider-agnostic API:
EmailPasswordProviderverifySession, get/create/revoke)SessionProviderRolesProviderEmailVerificationProviderClaimsProviderKey pieces:
initAuth/getAuth/authproxy insrc/auth/adapter.tsregisterAuthProvider/getAuthProviderregistry (default:supertokens)src/auth/supertokens.ts(includesAuthUser.thirdPartymapping from SuperTokens third-party login info)supertokens-nodeis marked optional viapeerDependenciesMeta(still required when using the default provider)ProfileValidationClaimis decoupled from SuperTokens'SessionClaimtype so claim checks can run through the adapter2. SuperTokens node 14 → 15 → 16
Dependency bumps in both packages:
packages/user:supertokens-node16.0.0 (peer>=16.0.0)packages/phone-auth: sameAPI adaptations throughout recipes and overrides:
tenantId(orSUPERTOKENS_DEFAULT_TENANT_ID) into session, roles, account-info, and passwordless callsuser.emails[0]/user.phoneNumbers[0]instead of singularemail/phoneNumbercreatedNewRecipeUserinstead ofcreatedNewUserGoogle/Github/Facebook/Apple) with{ config: { clients, thirdPartyId } }consumePasswordResetToken3. Core DB migration (automatic + re-runnable)
Added
packages/user/src/migrations/supertokens-core-v6.sqland wired it intorunMigrations:users/invitationsmigrations, before the server is readyst__appsandst__tenants(seeded withpublic)app_id/tenant_idto existing SuperTokens tables and rebuilds primary keys / indexes accordinglyIF EXISTS/IF NOT EXISTS/ON CONFLICT, includingDROP CONSTRAINT IF EXISTS) so a second plugin boot does not fail on already-migrated constraints4. Phone auth package
@prefabs.tech/fastify-phone-authaligned with the same SuperTokens v16 surface:>=16.0.0getCustomUserInputCode(tenantId, userContext)consumeCodeusesphoneNumbers[0],emails[0], andcreatedNewRecipeUser; passestenantIdintoUserRoles.addRoleToUserconsumeCodePOSTpassestenantIdtolistCodesByPreAuthSessionId; synthetic email enrichment writes toemails[]smsDelivery.override.sendSms— in development it logs and returns (Twilio skipped); the deprecatedcreateAndSendCustomTextMessagepath is removed5. Docs & tests
AuthUser/AuthSessionbreaks, peer install, and automatic migration>=16and re-runnable migration notesthirdParty)runMigrationswiring, andDROP CONSTRAINT IF EXISTScoverageadminSignUphandler unit testsBreaking changes for consumers
supertokens-node≥ 16 (and a Core version compatible with the v6 schema / multitenancy columns). The peer is optional only for fully customauthProviderapps.AuthUseris no longerSupertokensUser & User. Treat it as the auth-provider DTO; useUser/request.userfor database fields. Preferauth.claims/auth.sessionover raw SuperTokens session APIs from app code.runMigrations. Staging/prod DBs will receive thest__*multitenancy upgrade on first boot of this version — plan downtime / backups accordingly.auth/getAuth()/ exported auth types where possible; some recipe override signatures changed (tenant id, user field arrays, password-reset method name).clientsformat internally — verify Apple multi-client setups after upgrade.createAndSendCustomTextMessageor singularuser.email/user.phoneNumber/createdNewUserfrom passwordless responses must update.Test plan
pnpm --filter @prefabs.tech/fastify-user testpnpm --filter @prefabs.tech/fastify-phone-auth testpnpm lint && pnpm typecheck && pnpm build && pnpm testDROP CONSTRAINTfailures)emails[]/phoneNumbers[]and the newAuthUser/AuthSessiontypes