fix(customer-auth): make organization_id optional at registration
Requiring organization_id broke the current app, which does not send it. When it is left out and the database has exactly one organization, the customer now joins that one, so the app works unchanged. A sent organization_id must still exist, and with several organizations and none sent registration is refused with a clear message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a3cb7dd5fd
commit
8bf2fe5585
@@ -19,6 +19,8 @@ type CustomerAuthRepository interface {
|
||||
SetCustomerPassword(ctx context.Context, customerID string, passwordHash string) error
|
||||
// OrganizationExists reports whether an organization with this id exists.
|
||||
OrganizationExists(ctx context.Context, organizationID uuid.UUID) (bool, error)
|
||||
// OrganizationIDs returns up to limit organization ids.
|
||||
OrganizationIDs(ctx context.Context, limit int) ([]uuid.UUID, error)
|
||||
}
|
||||
|
||||
type customerAuthRepository struct {
|
||||
@@ -90,3 +92,12 @@ func (r *customerAuthRepository) OrganizationExists(ctx context.Context, organiz
|
||||
}
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
func (r *customerAuthRepository) OrganizationIDs(ctx context.Context, limit int) ([]uuid.UUID, error) {
|
||||
var ids []uuid.UUID
|
||||
err := r.db.WithContext(ctx).Table("organizations").Order("created_at").Limit(limit).Pluck("id", &ids).Error
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list organizations: %w", err)
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user