diff --git a/backend/ee/onyx/server/tenants/provisioning.py b/backend/ee/onyx/server/tenants/provisioning.py index 5328277ff663..aaf007a27e2a 100644 --- a/backend/ee/onyx/server/tenants/provisioning.py +++ b/backend/ee/onyx/server/tenants/provisioning.py @@ -55,7 +55,11 @@ logger = logging.getLogger(__name__) async def get_or_provision_tenant( email: str, referral_source: str | None = None, request: Request | None = None ) -> str: - """Get existing tenant ID for an email or create a new tenant if none exists.""" + """ + Get existing tenant ID for an email or create a new tenant if none exists. + This function should only be called after we have verified we want this user's tenant to exist. + It returns the tenant ID associated with the email, creating a new tenant if necessary. + """ if not MULTI_TENANT: return POSTGRES_DEFAULT_SCHEMA diff --git a/backend/onyx/auth/users.py b/backend/onyx/auth/users.py index df72c442df66..d8a995c7e9e5 100644 --- a/backend/onyx/auth/users.py +++ b/backend/onyx/auth/users.py @@ -587,14 +587,20 @@ class UserManager(UUIDIDMixin, BaseUserManager[User, uuid.UUID]): ) -> Optional[User]: email = credentials.username - # Get tenant_id from mapping table - tenant_id = await fetch_ee_implementation_or_noop( - "onyx.server.tenants.provisioning", - "get_or_provision_tenant", - async_return_default_schema, - )( - email=email, - ) + tenant_id: str | None = None + try: + tenant_id = fetch_ee_implementation_or_noop( + "onyx.server.tenants.provisioning", + "get_tenant_id_for_email", + None, + )( + email=email, + ) + except Exception as e: + logger.warning( + f"User attempted to login with invalid credentials: {str(e)}" + ) + if not tenant_id: # User not found in mapping self.password_helper.hash(credentials.password) diff --git a/web/src/app/auth/login/EmailPasswordForm.tsx b/web/src/app/auth/login/EmailPasswordForm.tsx index f63eefe38d51..fa8637503b86 100644 --- a/web/src/app/auth/login/EmailPasswordForm.tsx +++ b/web/src/app/auth/login/EmailPasswordForm.tsx @@ -61,6 +61,7 @@ export function EmailPasswordForm({ if (!response.ok) { setIsWorking(false); + const errorDetail = (await response.json()).detail; let errorMsg = "Unknown error"; if (typeof errorDetail === "object" && errorDetail.reason) { @@ -96,12 +97,13 @@ export function EmailPasswordForm({ } else { setIsWorking(false); const errorDetail = (await loginResponse.json()).detail; - let errorMsg = "Unknown error"; if (errorDetail === "LOGIN_BAD_CREDENTIALS") { errorMsg = "Invalid email or password"; } else if (errorDetail === "NO_WEB_LOGIN_AND_HAS_NO_PASSWORD") { errorMsg = "Create an account to set a password"; + } else if (typeof errorDetail === "string") { + errorMsg = errorDetail; } if (loginResponse.status === 429) { errorMsg = "Too many requests. Please try again later.";