SuperTokens Core provides comprehensive user management with support for multiple authentication methods per user, account linking, and user ID mapping for external identity systems.
SuperTokens distinguishes between two types of users:
Recipe User
A user authenticated through a single method (email/password, social login, etc.)
Primary User
A user with multiple authentication methods linked together
public class AuthRecipeUserInfo { public String id; // Primary user ID public boolean isPrimaryUser; public LoginMethod[] loginMethods; // All linked auth methods public String[] tenantIds; public long timeJoined;}public class LoginMethod { public String recipeUserId; // Unique per login method public RECIPE_ID recipeId; // emailpassword, thirdparty, passwordless public String email; public String phoneNumber; public ThirdParty thirdParty; public String[] tenantIds; public boolean verified;}
SignInUpResponse response = ThirdParty.signInUp( tenantIdentifier, storage, main, thirdPartyId, // "google", "github", etc. thirdPartyUserId, // User ID from provider email, isEmailVerified);
Before linking accounts, you must designate one as primary:
CreatePrimaryUserResult result = AuthRecipe.createPrimaryUser( main, appIdentifier, storage, recipeUserId);if (!result.wasAlreadyAPrimaryUser) { // User is now a primary user AuthRecipeUserInfo primaryUser = result.user;}
LinkAccountsResult result = AuthRecipe.linkAccounts( main, appIdentifier, storage, recipeUserId, // User to link primaryUserId // Primary user to link to);if (result.wasLinked) { // Account successfully linked AuthRecipeUserInfo linkedUser = result.user;}
boolean wasUnlinked = AuthRecipe.unlinkAccounts( main, appIdentifier, storage, recipeUserId);if (wasUnlinked) { // Recipe user is now independent}
If you unlink the recipe user that is also the primary user ID, and there are other linked accounts, the primary user will be deleted and all sessions revoked.
Once mapped, you can use external IDs in most operations:
// Get user by external IDAuthRecipeUserInfo user = AuthRecipe.getUserById( appIdentifier, storage, externalUserId // Automatically resolved);// Create session with external IDSessionInformationHolder session = Session.createNewSession( tenantIdentifier, storage, main, externalUserId, // Resolved to SuperTokens ID internally userDataInJWT, userDataInDatabase);
// Create user in SuperTokensSignUpResponse response = EmailPassword.signUp( tenantIdentifier, storage, main, email, password);// Map to your existing user IDUserIdMapping.createUserIdMapping( appIdentifier, storage, response.user.id, "your-system-user-123", null);// Now use either IDAuthRecipeUserInfo user = AuthRecipe.getUserById( appIdentifier, storage, "your-system-user-123" // Works!);