diff --git a/backend/account_v2/authentication_controller.py b/backend/account_v2/authentication_controller.py index cf1c245f69..f24f0e8c77 100644 --- a/backend/account_v2/authentication_controller.py +++ b/backend/account_v2/authentication_controller.py @@ -200,6 +200,10 @@ def set_user_organization(self, request: Request, organization_id: str) -> Respo ) if new_organization: + self.authentication_helper.create_initial_platform_key( + user=user, organization=organization + ) + try: self.auth_service.frictionless_onboarding( organization=organization, user=user @@ -207,9 +211,6 @@ def set_user_organization(self, request: Request, organization_id: str) -> Respo except MethodNotImplemented: logger.info("frictionless_onboarding not implemented") - self.authentication_helper.create_initial_platform_key( - user=user, organization=organization - ) logger.info( f"New organization created with Id {organization_id}", ) diff --git a/backend/account_v2/authentication_helper.py b/backend/account_v2/authentication_helper.py index 754b97afc4..adf5948d6b 100644 --- a/backend/account_v2/authentication_helper.py +++ b/backend/account_v2/authentication_helper.py @@ -55,24 +55,6 @@ def get_or_create_user_by_email(user_id: str, email: str) -> User: return user def create_initial_platform_key(self, user: User, organization: Organization) -> None: - """Create an initial platform key for the given user and organization. - - This method generates a new platform key with the specified parameters - and saves it to the database. The generated key is set as active and - assigned the name "Key #1". The key is associated with the provided - user and organization. - - Parameters: - user (User): The user for whom the platform key is being created. - organization (Organization): - The organization to which the platform key belongs. - - Raises: - Exception: If an error occurs while generating the platform key. - - Returns: - None - """ try: PlatformAuthenticationService.generate_platform_key( is_active=True, @@ -81,7 +63,7 @@ def create_initial_platform_key(self, user: User, organization: Organization) -> organization=organization, ) except Exception: - logger.error( + logger.exception( "Failed to create default platform key for " f"organization {organization.organization_id}" )