Laravel Telescope is not working in production with Laravel Voyager. How to secure /telescope/* routes in Laravel 7?

Viewed 2394

I'm using Laravel with Auth, Auth UI, Voyager admin panel, Telescope. Everything works fine untill I change APP_ENV=local to APP_ENV=production in .env file. When I change the .env file to production then I get the below error. screen shot of my issue is here.

Trying to get property 'name' of non-object

Basically I want to protect /telescope/*routes in production. But before doing that I am getting this error. I read the same issue in github similar issue github link. I think the answer is present in the link but im unable to digest it as im a newbie. Any help to fix this, and protecting telescope routes in production is much appreciated. I tried to create a Policy and give read permissions to the user via policy. But somehow im not able to fix it.

2 Answers

ok: its too easy - the only thing you have to do is:

php artisan make:policy -m User UserPolicy

thats it.

You can pass the array of email into the gate method in the TelescopeServiceProvider.php

       Gate::define('viewTelescope', function ($user) {
            return in_array($user->email, [
                'username@domain.com'
            ]);
        });

This will block everyone except the mentioned email of logged-in user.

Related