From 6ca1e3fba59d1416e6fa04b101e4a5c266f060e5 Mon Sep 17 00:00:00 2001 From: nexxo Date: Sat, 25 Jul 2026 18:31:08 +0200 Subject: [PATCH] fix(auth): create + link a Customer on public signup so the portal works pre-purchase Co-Authored-By: Claude Opus 4.8 --- app/Actions/Fortify/CreateNewUser.php | 15 ++++++++++++++- tests/Feature/Auth/RegisterTest.php | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/Actions/Fortify/CreateNewUser.php b/app/Actions/Fortify/CreateNewUser.php index cf4e428..a9cba15 100644 --- a/app/Actions/Fortify/CreateNewUser.php +++ b/app/Actions/Fortify/CreateNewUser.php @@ -39,10 +39,23 @@ class CreateNewUser implements CreatesNewUsers 'password' => $this->passwordRules(), ])->validate(); - return User::create([ + $user = User::create([ 'name' => $input['name'], 'email' => $input['email'], 'password' => Hash::make($input['password']), ]); + + // A public signup is a customer — create and link the record now so the + // portal (Billing::purchase, Settings, …) has a customer to work with + // before they buy a package. + Customer::query()->create([ + 'user_id' => $user->id, + 'name' => $input['name'], + 'email' => $input['email'], + 'locale' => app()->getLocale(), + 'status' => 'active', + ]); + + return $user; } } diff --git a/tests/Feature/Auth/RegisterTest.php b/tests/Feature/Auth/RegisterTest.php index af4bdd4..567edf4 100644 --- a/tests/Feature/Auth/RegisterTest.php +++ b/tests/Feature/Auth/RegisterTest.php @@ -22,6 +22,10 @@ it('registers a new account and signs in', function () { $user = User::query()->where('email', 'new@signup.test')->first(); expect($user)->not->toBeNull()->and($user->isOperator())->toBeFalse(); $this->assertAuthenticatedAs($user); + + // A linked customer is created so the portal has something to work with. + $customer = \App\Models\Customer::query()->where('user_id', $user->id)->first(); + expect($customer)->not->toBeNull()->and($customer->email)->toBe('new@signup.test'); }); it('refuses to register with an existing customer email (account-claim guard)', function () {