fix(auth): create + link a Customer on public signup so the portal works pre-purchase

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
feat/portal-design
nexxo 2026-07-25 18:31:08 +02:00
parent 39a1f708a1
commit 6ca1e3fba5
2 changed files with 18 additions and 1 deletions

View File

@ -39,10 +39,23 @@ class CreateNewUser implements CreatesNewUsers
'password' => $this->passwordRules(), 'password' => $this->passwordRules(),
])->validate(); ])->validate();
return User::create([ $user = User::create([
'name' => $input['name'], 'name' => $input['name'],
'email' => $input['email'], 'email' => $input['email'],
'password' => Hash::make($input['password']), '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;
} }
} }

View File

@ -22,6 +22,10 @@ it('registers a new account and signs in', function () {
$user = User::query()->where('email', 'new@signup.test')->first(); $user = User::query()->where('email', 'new@signup.test')->first();
expect($user)->not->toBeNull()->and($user->isOperator())->toBeFalse(); expect($user)->not->toBeNull()->and($user->isOperator())->toBeFalse();
$this->assertAuthenticatedAs($user); $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 () { it('refuses to register with an existing customer email (account-claim guard)', function () {