Skip to content

Commit 55b990b

Browse files
committed
Fix user resource tracking during onboarding
Issue: First user created during onboarding not tracked in billing system Root cause: User created BEFORE company exists, so company_uuid is null Solution: Create company FIRST, then set company_uuid before user creation Flow before: 1. User::create() - no company_uuid 2. Company created 3. assignCompany() - sets company_uuid after creation Flow after: 1. Company::create() - company exists first 2. Set company_uuid in attributes 3. User::create() - with company_uuid set 4. assignCompany() - maintains relationship This ensures ResourceCreatedListener can track the first user properly since it requires company_uuid to log usage to billing_resource_usage table. Related to fleetops driver creation fix (same issue, same solution).
1 parent 9dd7a72 commit 55b990b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Http/Controllers/Internal/v1/OnboardController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public function createAccount(OnboardRequest $request)
5757
'last_login' => $isAdmin ? now() : null,
5858
]);
5959

60+
// create company FIRST (required for billing resource tracking)
61+
$company = Company::create(['name' => $request->input('organization_name')]);
62+
63+
// set company_uuid before creating user (required for billing resource tracking)
64+
$attributes['company_uuid'] = $company->uuid;
65+
6066
// create user account
6167
$user = User::create($attributes);
6268

@@ -66,8 +72,7 @@ public function createAccount(OnboardRequest $request)
6672
// set the user type
6773
$user->setUserType($isAdmin ? 'admin' : 'user');
6874

69-
// create company
70-
$company = new Company(['name' => $request->input('organization_name')]);
75+
// set company owner
7176
$company->setOwner($user)->save();
7277

7378
// assign user to organization

0 commit comments

Comments
 (0)