Skip to main content

Overview

SuperTokens Core provides a high-performance bulk import system for migrating users from external authentication systems. It supports batched processing, multiple authentication methods per user, and preserves user metadata, roles, and verification status.

Key Features

High Volume

Import up to 10,000 users per API request

Multi-Method

Support for email/password, social, and passwordless

Account Linking

Automatically link multiple auth methods per user

Async Processing

Background processing with status tracking

Error Handling

Detailed error reporting per user

Password Migration

Import existing password hashes

Bulk Import Configuration

From io/supertokens/bulkimport/BulkImport.java:91-101:
number
Maximum users per POST request
number
Maximum users returned per GET request
number
Default pagination limit
number
Maximum users deleted per request
number
Interval between processing jobs (5 minutes)

User Import Structure

BulkImportUser Schema

Adding Users for Import

From io/supertokens/bulkimport/BulkImport.java:106-123:

Import Process

Processing Pipeline

From io/supertokens/bulkimport/BulkImport.java:209-239:
1

Process Login Methods

Create users for each authentication method (email/password, social, passwordless)
2

Link Accounts

Create primary users and link multiple login methods
3

Create User ID Mappings

Map SuperTokens IDs to external system IDs
4

Verify Emails

Mark emails as verified based on import data
5

Create TOTP Devices

Import 2FA devices
6

Import Metadata

Store custom user metadata
7

Assign Roles

Apply roles and permissions

Email/Password Import

From io/supertokens/bulkimport/BulkImport.java:383-426:
Password hashes can be imported directly (if you have them) or plain text passwords will be hashed automatically using your configured algorithm.

Third-Party Import

From io/supertokens/bulkimport/BulkImport.java:344-381:

Passwordless Import

Account Linking During Import

From io/supertokens/bulkimport/BulkImport.java:479-527:
When importing users with multiple login methods, one method must be marked as isPrimary: true. All other methods will be linked to this primary account.

Tenant Association

From io/supertokens/bulkimport/BulkImport.java:428-477:

Error Handling

Error Codes

From io/supertokens/bulkimport/BulkImport.java:86-87: All errors include unique error codes (E001-E046) for debugging:

Error Response Structure

Errors are mapped by user ID:

Checking Import Status

Get Import Users

From io/supertokens/bulkimport/BulkImport.java:125-152:

Import Status Types

NEW

User added to import queue

PROCESSING

Currently being imported

FAILED

Import failed with error

Count Users by Status

Deleting Import Users

From io/supertokens/bulkimport/BulkImport.java:154-157:
This deletes users from the import queue only. It does not affect successfully imported users.

Complete Import Example

Best Practices

Batch Processing

Import in batches of 1,000-5,000 users for optimal performance

Pre-Create Roles

Create all roles before importing users

Validate Data

Validate emails, phone numbers, and hashes before import

Monitor Status

Check import status and handle failures

Use External IDs

Map to your system IDs for easy integration

Test Small Batches

Test with 10-100 users before full migration

Performance Considerations

  • Transaction Batching: Users are processed in database transactions for consistency
  • Proxy Storage: Uses special proxy storage to avoid connection pool exhaustion
  • Background Processing: Cron job processes users every 5 minutes
  • Error Isolation: Errors in one user don’t affect others in the batch