Registry / security / better-auth-immigration

better-auth-immigration

JSON →
library0.1.1jsnpmunverified

A plugin for Better Auth (v1.5.0–1.x) that enables migration from legacy authentication systems by exchanging legacy tokens for Better Auth sessions. It provides a server-side plugin for verifying legacy credentials and resolving user identities, plus a client-side plugin for initiating the exchange. This package is in early development (v0.1.1) with no stable release yet.

npm install better-auth-immigration
INSTALL
IMPORT
SIG · BETTER-AUTH-IMMIGR
B
better-auth-immigration
securityjavascriptv0.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

legacyImmigration
import { legacyImmigration } from 'better-auth-immigration'
import { legacyImmigration } from 'better-auth-immigration/plugin'
Server-side plugin function; must be passed to BetterAuth plugins array.
legacyImmigrationClient
import { legacyImmigrationClient } from 'better-auth-immigration/client'
import { legacyImmigrationClient } from 'better-auth-immigration'
Client-side plugin function; exported from /client subpath.
authClient.legacyImmigration.exchange
await authClient.legacyImmigration.exchange({ token: legacyToken })
authClient.legacyImmigration({ token: legacyToken })
Method is called on the legacyImmigration property, not as a direct function.

Shows basic usage: importing server/client plugins, setting up legacy token verification and user resolution, and calling the exchange method.

import { betterAuth } from 'better-auth'; import { legacyImmigration } from 'better-auth-immigration'; import { createAuthClient } from 'better-auth/client'; import { legacyImmigrationClient } from 'better-auth-immigration/client'; // Server const auth = betterAuth({ plugins: [ legacyImmigration({ async verifyLegacyToken(token: string) { // Validate old JWT or token, return legacy user ID return { legacyUserId: token }; }, async resolveTransition({ legacyUserId }: { legacyUserId: string }) { // Map legacy user to Better Auth user ID return { userId: legacyUserId }; }, async onMigrated({ legacyUserId }: { legacyUserId: string }) { console.log('migrated', legacyUserId); } }) ] }); // Client const authClient = createAuthClient({ plugins: [legacyImmigrationClient()] }); // Exchange legacy token for session const oldToken = process.env.LEGACY_TOKEN ?? ''; await authClient.legacyImmigration.exchange({ token: oldToken });
Debug
Known issues
gotchaThe client-side plugin is exported from 'better-auth-immigration/client', not the main package. Importing from the main package will not include the client types.
fix
Use import { legacyImmigrationClient } from 'better-auth-immigration/client'.
affects: >=0.1.0
gotchaThe server plugin requires all three callbacks: verifyLegacyToken, resolveTransition, and onMigrated. Omitting any will cause a runtime error.
fix
Provide all three asynchronous callback functions to legacyImmigration().
affects: >=0.1.0
breakingWorks exclusively with Better Auth v1.5.0+. Earlier versions are incompatible.
fix
Ensure better-auth version is >=1.5.0 and <2.
affects: >=1.5.0 <2
Errors
Common errors & fixes
legacyImmigration is not a function
Incorrect import path or missing default export.
fix
Use import { legacyImmigration } from 'better-auth-immigration' (not a subpath).
Cannot find module 'better-auth-immigration/client'
The client-side subpath is not resolved, possibly due to ESM configuration or outdated node_modules.
fix
Ensure better-auth-immigration v0.1.1 is installed and your module system supports subpath exports (Node.js 16+ with ESM).
Uncaught TypeError: authClient.legacyImmigration.exchange is not a function
Client plugin not registered or misconfigured.
fix
Ensure legacyImmigrationClient() is added to createAuthClient plugins array.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies
better-authrequiredpeer dependency for server-side plugin and client types
Agent activity
24 hits · last 30 days
node
22
Amazon
1
Resources
better-auth-immigration — npm install better-auth-immigration · libregistry