# Migrate to Pontive

> Move users, password hashes, TOTP, social sign-ins and organizations into Pontive from Auth0, Clerk, Firebase, Supabase, Cognito or NextAuth, dry run first and revertable, then switch your app to pontkit.

Source: https://www.pontive.com/docs/guides/migrate

A migration has two halves: **move the users**, with the `pontive migrate` CLI or the import API,
then **switch the app** from the old provider's SDK to pontkit. Pick your provider:

<Cards>
<Card title="Auth0" href="/docs/guides/migrate/auth0">
Users, bcrypt hashes from Auth0 support, social identities, organizations with roles.
</Card>

<Card title="Clerk" href="/docs/guides/migrate/clerk">
Users, password digests and TOTP from the dashboard export, organizations with roles.
</Card>

<Card title="Firebase" href="/docs/guides/migrate/firebase">
Users and Firebase scrypt hashes, verified against your project's hash parameters.
</Card>

<Card title="Supabase" href="/docs/guides/migrate/supabase">
Users, bcrypt hashes and TOTP from the auth schema; your data stays in Supabase.
</Card>

<Card title="Amazon Cognito" href="/docs/guides/migrate/cognito">
Profiles, and groups as roles. Cognito exports no hashes, so password users reset.
</Card>

<Card title="NextAuth.js (Auth.js)" href="/docs/guides/migrate/nextauth">
No exporter: write the import file from the adapter's tables with one SQL query.
</Card>
</Cards>

## How a migration works [#how-a-migration-works]

- **A migration source** (`msrc_…`) names the system users are leaving. Each imported user keeps
  their id there as a **legacy subject**, and Firebase's hash parameters live on the source.
- **An import run** (`uimp_…`) holds one migration's options, counters and a record per row.
  Users are sent in batches of 100, then organizations in batches of 100 with up to 1,000 members.
- **Dry run by default.** Every batch plans unless told to apply, and the CLI always dry-runs the
  whole file before it writes anything.
- **Matching is by the old id, never by email.** A row matches an existing user by its legacy
  subject, else its `external_id`. A row whose email belongs to a user it did not match fails with
  `identifier_conflict`, so an import can never attach a password or identity to an account someone
  else registered. Re-sending a batch skips what it already created.
- **Organizations come after their users**, each with its members, and a new one needs a member
  with the `owner` role.
- **A run can be reverted** while its records exist (90 days after its last batch).

Nothing is emailed to imported users: no welcome, verification or invitation.

## What your users notice [#what-your-users-notice]

| They had | In Pontive |
| --- | --- |
| A password, with its hash exported | They sign in with the same password. It is re-hashed natively at that first sign-in. If it breaks your password policy they are asked to change it, unless the run allows weak passwords. |
| A password whose hash was not exported | They use **Forgot password** on the sign-in page the first time. |
| TOTP | Their authenticator app keeps working, when the secret was exported and the run names apps to store it under. Otherwise they enroll again. |
| Google, GitHub, Apple or a custom OIDC sign-in | Imported identities sign in directly. Without them, the first sign-in links to the account by verified email. |
| Microsoft or Entra ID sign-in | Not portable: their subject differs per app registration. They link by verified email at the first sign-in. |
| A session in the old system | They sign in once more after the cutover. |

Linking by email needs **auto-link by email** on in [account linking](/docs/api-reference/management/account-linking)
(on by default), a provider that vouches for the address, and an account whose email is verified.

## Before you start [#before-you-start]

1. **Use a development instance first.** Import there, sign in as a few migrated users, then repeat
   against production.
2. **Create a secret key with the `admin` role** on that instance. Migration sources and credential
   imports (hashes, TOTP secrets, identities) are open to the instance's owners and admins only,
   and never to a token acting for a user, so an AI client using the Pontive MCP server can import
   profiles but never credentials.
3. **Run the CLI with `npx`.** It is the `pontive` package on npm, version 1.19 or later. It reads
   the key from the environment, never a flag, and picks the API from the key's region.

```sh
export PONTIVE_SECRET_KEY=pontive_sk_test_us_...
npx pontive@latest migrate --help
```

The commands every guide uses:

| Command | Does |
| --- | --- |
| `migrate source create --name <name> --type <type>` | Creates the migration source; prints its `msrc_…` id. |
| `migrate export <provider> [--out file]` | Writes users, then organizations, as `pontive-users/v1` NDJSON, mode `0600`. |
| `migrate import <file> --source msrc_…` | Creates a run and dry-runs every batch. Add `--apply` to write after the dry run and a confirmation. |
| `migrate run <provider> --source msrc_…` | Export and import in one go, with nothing written to disk. |
| `migrate status [uimp_…]` | A run with its options and counters, or the latest runs. |
| `migrate records uimp_… [--outcome failed] [--kind user\|organization]` | Every record of a run. |
| `migrate revert uimp_… [--apply]` | What the run created that can be deleted; with `--apply`, deletes it. |

In a coding agent (`CLAUDECODE`, `CURSOR_AGENT`, `CODEX_SANDBOX`, `GEMINI_CLI` or `CI` set, or
`--json`) the CLI prints one JSON object and never prompts, so `--apply` also needs `--yes`. Read the
dry run before giving it.

## Import options [#import-options]

A run's options are fixed when it is created, which the first dry run does. Change a flag before
anything is applied and the CLI starts a new run; once a batch is applied, a different flag is
refused.

| Flag | |
| --- | --- |
| `--identity-connection google=app_…:google` | Import identities of that type into that app's auth connection (the connection's slug after the colon). Repeatable. Types with no mapping are left out and counted, and those users link by email. |
| `--totp-app app_…` | Store imported TOTP secrets under that app's issuer. The app must have TOTP on. Repeatable. Without one, TOTP secrets are left out and those users enroll again. |
| `--role-map source_role=pontive_role,…` | Organization roles, and root roles (a user's `root_roles`, such as Cognito's groups). A member holding a role the map does not name is left out of the organization or the root and reported as `role_not_mapped`; the user is still imported. Without a map, roles are sent as exported. |
| `--on-existing skip\|update` | What a row matching an existing user does. `update` writes the profile, metadata and verified flags, and replaces credentials only while the user has not chosen a password in Pontive. Default `skip`. |
| `--allow-weak-passwords` | An imported password that breaks the password policy is not forced to change at first sign-in. |
| `--no-events` | No `pontive.user.created` webhook per imported user. Audit entries are written either way. |
| `--name <name>` | The run's name. |
| `--delete-after` | With `--apply`, delete the file and its state once applied. |

Roles must exist before an import names them: organization roles on the `org` type, root roles on
the `root` type. Every instance has `owner` and `admin`; create others with
[`POST /v1/authz/resource-types/{type}/roles`](/docs/api-reference/management/roles) or the
[Pontive MCP server](/docs/guides/pontive-mcp-server).

**Root roles.** A user line's `root_roles` are the user's roles on the instance, outside any
organization. The import API takes no root memberships, so the CLI adds each imported user to the
root itself, with the mapped roles, once the user's batch is applied. The dry run checks the roles
exist on `root` and adds no one. `owner` is never granted this way, a deactivated user is not added,
and a user who is a root member already keeps their roles unless the run uses `--on-existing update`.
The secret key needs `sys:root:grant`.

## Reading the report [#reading-the-report]

The dry run and the apply both end with counts for users, organizations and root members (created,
updated, skipped, failed), failures grouped by error code with each row's key, the warnings, and how many
password users have no hash. The codes you are most likely to see:

| Code | Means | Fix |
| --- | --- | --- |
| `identifier_conflict` | Another Pontive user has this email, phone or username | Decide which account wins; the import never merges them. |
| `owners_required` | A new organization has no member with `owner` | Map a source role to `owner` with `--role-map`. |
| `role_not_found`, `role_not_mapped` | A role is not an `org` role (or a `root` role, for `root_roles`), or the map does not name it | Create the role, or add it to the map. |
| `password_hash_invalid`, `hasher_unsupported` | The hash could not be read | Fix or remove `password_hash` in those rows; the users then reset. |
| `totp_unsupported` | The secret is not SHA-1, 6 digits, 30 seconds | Those users enroll again. |

In a dry run, an organization whose members are users the same import creates is reported as
*pending users*, not failed. `import` keeps `.pontive-import-state.json` beside the file, so an
interrupted `--apply` continues from the next batch when run again.

## Cut over [#cut-over]

1. **Sign in on the development instance** as a password user, a TOTP user and a social user.
2. **Import into production** with a production secret key (`pontive_sk_live_…`), the same commands
   and a production migration source.
3. **Catch late sign-ups.** Just before switching, export again to a new file and import it into the
   same run, so one revert still covers everything; rows already imported are skipped:
   `npx pontive@latest migrate import final.ndjson --run uimp_… --apply`.
4. **Deploy the app on pontkit**, with the production app's redirect URIs and allowed origins
   registered in Pontive.
5. **Turn off the old system's emails** and sign-ups, so nobody receives two of each.
6. **Webhooks.** Every imported user fires `pontive.user.created` with
   `context.source: "import"` and the run's id, unless the run used `--no-events`. A consumer that
   sends welcome emails should skip those.
7. **Old ids in your database.** By default the exporters set `external_id` to the old provider's id.
   If your tables key users by it, put it in the access token with the app's
   [claims template](/docs/api-reference/management/apps):

   ```json
   { "legacy_user_id": "{{ user.external_id }}" }
   ```

8. **Watch passwords move.** `npx pontive@latest migrate source get msrc_…` shows how many imported
   passwords still wait for their user's first sign-in.

## Revert [#revert]

```sh
npx pontive@latest migrate revert uimp_...          # dry run: what would be deleted, what kept
npx pontive@latest migrate revert uimp_... --apply  # deletes it
```

Revert deletes, outright so the emails are free for a re-import, the users the run created that have
not signed in since, and the organizations it created that have no other members. It keeps and lists
users who signed in (`signed_in`), organizations with other members (`has_other_members`), the owner
of an organization it keeps (`owns_organization`), and what it may not delete (`forbidden`). What the
run updated is not undone. A reverted run takes no more batches.

## Any other system: the file format [#any-other-system-the-file-format]

`pontive-users/v1` is NDJSON: one JSON object per line, users before organizations. A `user` line is
[`POST /v1/users/import`](/docs/api-reference/management/user-imports)'s user object with `kind`
beside its fields, plus the format's own `root_roles` (the user's roles on the instance, which the CLI
grants itself), an `organization` line `POST /v1/organizations/import`'s organization object. The
header and summary lines are optional.

```json
{"format":"pontive-users/v1","source_type":"other"}
{"kind":"user","legacy_subject":"42","external_id":"42","email":"jane@acme.com","email_verified":true,"name":"Jane Doe","password_hash":{"hasher":"bcrypt","value":"$2b$10$..."},"root_roles":["support"]}
{"kind":"organization","external_id":"acme","name":"Acme Corp","members":[{"legacy_subject":"42","roles":["owner"]}]}
```

`legacy_subject` needs a migration source on the run (`--source`). `password` (plaintext) and
`password_hash` are exclusive; plaintext is hashed and checked against the policy at import.

| `hasher` | `value` |
| --- | --- |
| `bcrypt` | `$2a$`, `$2b$`, `$2y$` |
| `argon2` | `$argon2id$`, `$argon2i$` |
| `scrypt` | PHC `$scrypt$…`, or the raw hash with `salt` and `params` |
| `firebase_scrypt` | base64 hash with `salt`; the parameters on the source |
| `pbkdf2` | passlib's `$pbkdf2…$` forms, PHC, or raw with `salt` and `params` |
| `django` | `pbkdf2_sha256$…`, `pbkdf2_sha1$…`, `argon2$…`, `bcrypt_sha256$…`, `bcrypt$…` |
| `werkzeug` | `pbkdf2:sha256:…`, `scrypt:…` |
| `aspnet_identity` | base64 v2 and v3 |
| `wordpress` | phpass `$P$`, `$H$`, and `$wp$2y$` |
| `ldap` | `{SSHA}`, `{SSHA256}`, `{SSHA512}`, `{SHA}` |
| `digest` | hex or base64 MD5 or SHA digest, with `salt` and `params.salt_position` |

Hashes weaker than OWASP's current minimum (digests, LDAP, phpass, Firebase's scrypt, low-cost
bcrypt or PBKDF2) are wrapped in argon2id at import, so no weak hash is stored. HMAC with a key,
peppers and crypt(3) `$1$`, `$5$`, `$6$` are refused with `hasher_unsupported`.

The API takes the same objects directly; see [Migration sources](/docs/api-reference/management/migration-sources)
and [User imports](/docs/api-reference/management/user-imports).

## Not covered yet [#not-covered-yet]

- **Lazy migration** (checking a password against the old system at first sign-in) and **session
  carry-over** are not built: users without an exported hash reset, and everyone signs in once more.
- Users without an email (phone-only) are left out: Pontive requires one.
- SMS factors and passkeys do not move; users enroll again.
- Resource memberships, groups and pending invitations are not imported. Root roles are, from a
  user line's `root_roles`.
- There is no migration page in the dashboard yet: use the CLI or the API.
