POST /user/remove
Delete a user from SuperTokens. Optionally delete all linked accounts as well.Request Body
Parameters
- userId (string, required): The user ID to delete. Can be either a SuperTokens user ID or an external user ID (if user ID mapping is configured)
-
removeAllLinkedAccounts (boolean, optional): Whether to delete all linked accounts. Defaults to
truetrue: Deletes the user and all linked login methods (when account linking is enabled)false: Deletes only the specified user/login method
Response
Success Response
Example Usage
Delete User and All Linked Accounts
Delete Only Specific Login Method
Delete User by External ID
If you have user ID mapping configured:Behavior Details
Account Linking
When account linking is enabled:-
removeAllLinkedAccounts: true (default):
- Deletes the primary user
- Deletes all recipe users linked to the primary user
- Removes all sessions for all linked accounts
- Removes all metadata, roles, and permissions
-
removeAllLinkedAccounts: false:
- Deletes only the specified recipe user
- If the recipe user is linked to a primary user, it’s unlinked first
- Other linked accounts remain intact
Data Cleanup
When a user is deleted, the following data is also removed:- User sessions
- User metadata
- User roles and permissions
- Email verification tokens
- Password reset tokens
- User ID mappings
- Third-party user associations
- Passwordless codes and devices
Tenant Association
If the user is associated with multiple tenants:- The user is removed from all tenants
- Tenant-specific data is cleaned up
- Other users in those tenants are not affected
Implementation Details
- Located in:
src/main/java/io/supertokens/webserver/api/core/DeleteUserAPI.java:37 - This is an app-specific API
- The API enforces public tenant access for app-specific operations
- Supports user ID mapping: accepts both SuperTokens IDs and external IDs
- If the user doesn’t exist, the operation succeeds silently (idempotent)
- Deletion is performed within a transaction for data consistency
Idempotent Operation
This endpoint is idempotent:- Calling it multiple times with the same user ID has the same effect as calling it once
- No error is returned if the user doesn’t exist
- Always returns
{"status": "OK"}
Use Cases
GDPR Compliance
Delete user data when requested:Account Closure
Remove user account when they close their account:Unlinking Login Methods
Remove a specific login method without deleting the user:Test Data Cleanup
Clean up test users after testing:Security Considerations
- Authorization: Ensure proper authorization before calling this endpoint
- Audit Logging: Log user deletions for compliance and security auditing
- Confirmation: Implement a confirmation step in your UI before deletion
- Backup: Consider backing up user data before deletion
- Associated Data: Handle cleanup of user data in your own application database
Best Practices
- Always use
removeAllLinkedAccounts: trueunless you have a specific reason not to - Implement a “soft delete” in your application if you need to retain data
- Clean up user data in your own database after deleting from SuperTokens
- Revoke any API keys or access tokens issued to the user
- Notify the user (if applicable) that their account has been deleted
- Document your data retention policy
Related Endpoints
- Get User by ID - Retrieve user information before deletion
- List Users - List users to find accounts to delete
- Unlink Account - Unlink accounts without deletion