From 020f810a7ed8ab37589dde013644a26251ccebc7 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 26 Jun 2022 19:22:06 -0600 Subject: [PATCH] Add TelescopeServiceProvider --- app/Providers/TelescopeServiceProvider.php | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 app/Providers/TelescopeServiceProvider.php diff --git a/app/Providers/TelescopeServiceProvider.php b/app/Providers/TelescopeServiceProvider.php new file mode 100644 index 000000000..f2ce31c0d --- /dev/null +++ b/app/Providers/TelescopeServiceProvider.php @@ -0,0 +1,75 @@ +hideSensitiveRequestDetails(); + + Telescope::filter(function (IncomingEntry $entry) { + if ($this->app->environment('local')) { + return true; + } + + return $entry->isReportableException() || + $entry->isFailedRequest() || + $entry->isFailedJob() || + $entry->isScheduledTask() || + $entry->hasMonitoredTag(); + }); + } + + /** + * Prevent sensitive request details from being logged by Telescope. + * + * @return void + */ + protected function hideSensitiveRequestDetails() + { + if ($this->app->environment('local')) { + return; + } + + Telescope::hideRequestParameters(['_token']); + + Telescope::hideRequestHeaders([ + 'cookie', + 'x-csrf-token', + 'x-xsrf-token', + ]); + } + + /** + * Register the Telescope gate. + * + * This gate determines who can access Telescope in non-local environments. + * + * @return void + */ + protected function gate() + { + Gate::define('viewTelescope', function ($user) { + if(!config('telescope.enabled')) { + return false; + } + return in_array($user->email, [ + 'danielsupernault@gmail.com', + 'me@dansup.com' + ]); + }); + } +}