Skip to content

Error codes ​

The plugin exports TENANT_AUTH_ERROR_CODES from both the server and client packages.

ts
import { TENANT_AUTH_ERROR_CODES } from "better-auth-tenancy";
// or
import { TENANT_AUTH_ERROR_CODES } from "better-auth-tenancy/client";

Codes ​

CodeMessage
TENANT_ID_REQUIREDTenant id is required
TENANT_NOT_FOUNDTenant not found
TENANT_ALREADY_EXISTSA tenant with this slug already exists
TENANT_MANAGEMENT_NOT_ALLOWEDYou are not allowed to manage tenants or tenant OAuth configurations
TENANT_NOT_OWNEDYou do not own this tenant
MEMBER_ALREADY_EXISTSThis user is already a member of the tenant
MEMBER_NOT_FOUNDTenant member not found
CANNOT_REMOVE_LAST_OWNERCannot remove or demote the last owner of the tenant
PLATFORM_USER_NOT_FOUNDPlatform user not found
PLATFORM_USER_AMBIGUOUSMultiple platform users share this email
PLATFORM_USER_REQUIREDProvide a platform user id or email
OAUTH_CREDENTIAL_DECRYPT_FAILEDFailed to decrypt stored OAuth credentials
USER_ALREADY_EXISTSA user with this email already exists for this tenant
INVALID_EMAIL_OR_PASSWORDInvalid email or password
EMAIL_NOT_VERIFIEDEmail is not verified
EMAIL_PASSWORD_NOT_ENABLEDEmail and password sign in is not enabled
PROVIDER_NOT_FOUNDOAuth provider not found. Configure it for the tenant or in the auth config
UNSUPPORTED_PROVIDERThis provider is not a supported built-in social provider
OAUTH_CONFIG_NOT_FOUNDOAuth configuration not found for this tenant
FAILED_TO_CREATE_USERFailed to create user
FAILED_TO_CREATE_SESSIONFailed to create session
INVALID_CALLBACK_URLInvalid callbackURL
INVALID_VERIFICATION_TOKENInvalid or unsupported verification token
SESSION_TENANT_MISMATCHThis session cannot be used for this tenant or host
INVALID_SLUGSlug must be 2-63 lowercase letters, digits, or hyphens, and cannot start or end with a hyphen
SLUG_RESERVEDThis slug is reserved
INVITE_REQUIREDA valid invite is required to sign up for this tenant
INVITE_INVALIDInvite is invalid or does not match this sign-up
INVITE_EXPIREDInvite has expired
INVITE_NOT_FOUNDInvite not found
INVITE_ALREADY_EXISTSA pending invite already exists for this email
EMAIL_DOMAIN_NOT_ALLOWEDEmail domain is not allowed for this tenant

Usage ​

The plugin registers these codes on $ERROR_CODES for typed error handling in Better Auth clients:

ts
const authClient = createAuthClient({
  plugins: [tenantAuthClient()],
});

// authClient.$ERROR_CODES.TENANT_NOT_FOUND

HTTP status mapping follows Better Auth conventions (e.g. TENANT_NOT_FOUND → 404, TENANT_MANAGEMENT_NOT_ALLOWED → 403).

Released under the MIT License.