Make auth tab optional and show only user name (#1578)

* Make auth tab optional and show only user name

* Update LaravelDebugbar.php

* Add config

---------

Co-authored-by: Barry vd. Heuvel <barryvdh@gmail.com>
This commit is contained in:
PaolaRuby 2024-04-01 11:36:46 -05:00 committed by GitHub
parent 1a27ae0250
commit 8916325a5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 5 deletions

View File

@ -208,6 +208,7 @@ return [
],
'auth' => [
'show_name' => true, // Also show the users name/email in the debugbar
'show_guards' => true, // Show the guards that are used
],
'db' => [
'with_params' => true, // Render SQL with the parameters substituted

View File

@ -25,6 +25,9 @@ class MultiAuthCollector extends DataCollector implements Renderable
/** @var bool */
protected $showName = false;
/** @var bool */
protected $showGuardsData = true;
/**
* @param \Illuminate\Auth\AuthManager $auth
* @param array $guards
@ -44,6 +47,15 @@ class MultiAuthCollector extends DataCollector implements Renderable
$this->showName = (bool) $showName;
}
/**
* Set to hide the guards tab, and show only name
* @param bool $showGuardsData
*/
public function setShowGuardsData($showGuardsData)
{
$this->showGuardsData = (bool) $showGuardsData;
}
/**
* @{inheritDoc}
*/
@ -79,6 +91,9 @@ class MultiAuthCollector extends DataCollector implements Renderable
}
$data['names'] = rtrim($names, ', ');
if (!$this->showGuardsData) {
unset($data['guards']);
}
return $data;
}
@ -142,14 +157,16 @@ class MultiAuthCollector extends DataCollector implements Renderable
*/
public function getWidgets()
{
$widgets = [
"auth" => [
$widgets = [];
if ($this->showGuardsData) {
$widgets["auth"] = [
"icon" => "lock",
"widget" => "PhpDebugBar.Widgets.VariableListWidget",
"map" => "auth.guards",
"default" => "{}"
]
];
"default" => "{}",
];
}
if ($this->showName) {
$widgets['auth.name'] = [

View File

@ -492,6 +492,9 @@ class LaravelDebugbar extends DebugBar
$this['auth']->setShowName(
$config->get('debugbar.options.auth.show_name')
);
$this['auth']->setShowGuardsData(
$config->get('debugbar.options.auth.show_guards', true)
);
} catch (Exception $e) {
$this->addCollectorException('Cannot add AuthCollector', $e);
}