Fix extra tenant mystery (#4197)

* fix extra tenant mystery

* nit
This commit is contained in:
pablonyx
2025-03-06 10:06:49 -08:00
committed by GitHub
parent cec05c5ee9
commit 92faca139d
3 changed files with 22 additions and 10 deletions

View File

@@ -55,7 +55,11 @@ logger = logging.getLogger(__name__)
async def get_or_provision_tenant( async def get_or_provision_tenant(
email: str, referral_source: str | None = None, request: Request | None = None email: str, referral_source: str | None = None, request: Request | None = None
) -> str: ) -> 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: if not MULTI_TENANT:
return POSTGRES_DEFAULT_SCHEMA return POSTGRES_DEFAULT_SCHEMA

View File

@@ -587,14 +587,20 @@ class UserManager(UUIDIDMixin, BaseUserManager[User, uuid.UUID]):
) -> Optional[User]: ) -> Optional[User]:
email = credentials.username email = credentials.username
# Get tenant_id from mapping table tenant_id: str | None = None
tenant_id = await fetch_ee_implementation_or_noop( try:
tenant_id = fetch_ee_implementation_or_noop(
"onyx.server.tenants.provisioning", "onyx.server.tenants.provisioning",
"get_or_provision_tenant", "get_tenant_id_for_email",
async_return_default_schema, None,
)( )(
email=email, email=email,
) )
except Exception as e:
logger.warning(
f"User attempted to login with invalid credentials: {str(e)}"
)
if not tenant_id: if not tenant_id:
# User not found in mapping # User not found in mapping
self.password_helper.hash(credentials.password) self.password_helper.hash(credentials.password)

View File

@@ -61,6 +61,7 @@ export function EmailPasswordForm({
if (!response.ok) { if (!response.ok) {
setIsWorking(false); setIsWorking(false);
const errorDetail = (await response.json()).detail; const errorDetail = (await response.json()).detail;
let errorMsg = "Unknown error"; let errorMsg = "Unknown error";
if (typeof errorDetail === "object" && errorDetail.reason) { if (typeof errorDetail === "object" && errorDetail.reason) {
@@ -96,12 +97,13 @@ export function EmailPasswordForm({
} else { } else {
setIsWorking(false); setIsWorking(false);
const errorDetail = (await loginResponse.json()).detail; const errorDetail = (await loginResponse.json()).detail;
let errorMsg = "Unknown error"; let errorMsg = "Unknown error";
if (errorDetail === "LOGIN_BAD_CREDENTIALS") { if (errorDetail === "LOGIN_BAD_CREDENTIALS") {
errorMsg = "Invalid email or password"; errorMsg = "Invalid email or password";
} else if (errorDetail === "NO_WEB_LOGIN_AND_HAS_NO_PASSWORD") { } else if (errorDetail === "NO_WEB_LOGIN_AND_HAS_NO_PASSWORD") {
errorMsg = "Create an account to set a password"; errorMsg = "Create an account to set a password";
} else if (typeof errorDetail === "string") {
errorMsg = errorDetail;
} }
if (loginResponse.status === 429) { if (loginResponse.status === 429) {
errorMsg = "Too many requests. Please try again later."; errorMsg = "Too many requests. Please try again later.";