mirror of
https://github.com/koel/koel
synced 2024-11-24 21:23:06 +00:00
33 lines
801 B
PHP
33 lines
801 B
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Str;
|
|
use Jackiedo\DotenvEditor\DotenvEditor;
|
|
|
|
class GenerateJwtSecretCommand extends Command
|
|
{
|
|
protected $name = 'koel:generate-jwt-secret';
|
|
protected $description = 'Set the JWTAuth secret key used to sign the tokens';
|
|
private $dotenvEditor;
|
|
|
|
public function __construct(DotenvEditor $dotenvEditor)
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->dotenvEditor = $dotenvEditor;
|
|
}
|
|
|
|
public function handle(): void
|
|
{
|
|
if (config('jwt.secret')) {
|
|
$this->comment('JWT secret exists -- skipping');
|
|
|
|
return;
|
|
}
|
|
|
|
$this->info('Generating JWT secret');
|
|
$this->dotenvEditor->setKey('JWT_SECRET', Str::random(32))->save();
|
|
}
|
|
}
|