Skip to content

Commit f3e3436

Browse files
committed
Add project name to default token name
1 parent 41904c8 commit f3e3436

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/Commands/Setup.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ public function handle(): int
7676
return 0;
7777
}
7878

79-
protected function getComputerName(): ?string
80-
{
81-
return gethostname() ?: null;
82-
}
83-
8479
protected function api(string $path, string $email, string $password, array $extra = []): Response
8580
{
8681
return Http::acceptJson()->withoutRedirecting()->put(static::$endpoint . '/' . $path, array_merge([

src/Concerns/GeneratesToken.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protected function getToken(string $email, string $password): Response
1515
{
1616
$tokenName = null;
1717
while (! $tokenName) {
18-
$input = $this->anticipate('Token name', [$this->getComputerName()], $this->getComputerName());
18+
$input = $this->anticipate('Token name', [$this->getDefaultTokenName()], $this->getDefaultTokenName());
1919

2020
$validator = Validator::make(['token' => $input], [
2121
'token' => 'required',
@@ -40,6 +40,15 @@ protected function generateToken(string $email, string $password, string $tokenN
4040
return $this->api('token', $email, $password, ['token_name' => $tokenName]);
4141
}
4242

43+
protected function getDefaultTokenName(): ?string
44+
{
45+
if (gethostname()) {
46+
return config('app.name') . ' @ ' . gethostname();
47+
}
48+
49+
return config('app.name');
50+
}
51+
4352
protected function writeTokenToAuthJson(string $token): void
4453
{
4554
$authJson = base_path('auth.json');

tests/TokenTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ public function token_name_defaults_to_the_computer_hostname()
3131
'lean-admin.dev/install/auth' => Http::response(['message' => 'OK'], 200, ['Content-Type' => 'application/json']),
3232
]);
3333

34+
$defaultName = 'Laravel @ ' . gethostname();
35+
3436
$this->artisan('lean:setup')
3537
->expectsQuestion("What's your email?", 'samuel.stancl@gmail.com')
3638
->expectsQuestion("What's your password?", 'foo')
37-
->expectsChoice('Token name', gethostname(), [gethostname()]) // <--
39+
->expectsChoice('Token name', $defaultName, [$defaultName]) // <--
3840
->assertExitCode(0);
3941
}
4042

0 commit comments

Comments
 (0)