Skip to content

Commit 49691bc

Browse files
committed
fix: Can't create new users via CLI if username is disabled
1 parent 62df7fd commit 49691bc

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/Commands/User.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ private function setValidationRules(): void
220220

221221
$rules = $validationRules->getRegistrationRules();
222222

223-
// Remove `strong_password` because it only supports use cases
223+
// Remove `strong_password` rule because it only supports use cases
224224
// to check the user's own password.
225225
$passwordRules = $rules['password']['rules'];
226226
if (is_string($passwordRules)) {
@@ -241,11 +241,10 @@ private function setValidationRules(): void
241241

242242
$rules['password']['rules'] = $passwordRules;
243243

244-
$this->validationRules = [
245-
'username' => $rules['username'],
246-
'email' => $rules['email'],
247-
'password' => $rules['password'],
248-
];
244+
// Remove `password_confirm` field.
245+
unset($rules['password_confirm']);
246+
247+
$this->validationRules = $rules;
249248
}
250249

251250
/**
@@ -258,10 +257,13 @@ private function create(?string $username = null, ?string $email = null): void
258257
{
259258
$data = [];
260259

261-
if ($username === null) {
260+
if ($username === null && isset($this->validationRules['username'])) {
262261
$username = $this->prompt('Username', null, $this->validationRules['username']['rules']);
263262
}
264263
$data['username'] = $username;
264+
if ($username === null) {
265+
unset($data['username']);
266+
}
265267

266268
if ($email === null) {
267269
$email = $this->prompt('Email', null, $this->validationRules['email']['rules']);

0 commit comments

Comments
 (0)