Skip to content

Commit

Permalink
Make auth tab optional and show only user name (#1578)
Browse files Browse the repository at this point in the history
* Make auth tab optional and show only user name

* Update LaravelDebugbar.php

* Add config

---------

Co-authored-by: Barry vd. Heuvel <[email protected]>
  • Loading branch information
PaolaRuby and barryvdh authored Apr 1, 2024
1 parent 1a27ae0 commit 8916325
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions config/debugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
],
'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
Expand Down
27 changes: 22 additions & 5 deletions src/DataCollector/MultiAuthCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,6 +47,15 @@ public function setShowName($showName)
$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}
*/
Expand Down Expand Up @@ -79,6 +91,9 @@ public function collect()
}

$data['names'] = rtrim($names, ', ');
if (!$this->showGuardsData) {
unset($data['guards']);
}

return $data;
}
Expand Down Expand Up @@ -142,14 +157,16 @@ public function getName()
*/
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'] = [
Expand Down
3 changes: 3 additions & 0 deletions src/LaravelDebugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,9 @@ public function __toString(): string
$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);
}
Expand Down

0 comments on commit 8916325

Please sign in to comment.