1

I tried to report the issue on github, but my issue was closed in like 2 hours and the response was: "Try another sites for answers". Did I do something wrong? Here is my problem:

I have a different guard for my admins. My guard is not the default guard.

`'defaults' => [ 'guard' => 'web', 'passwords' => 'users', ],

/* |--------------------------------------------------------------------------

Authentication Guards Next, you may define every authentication guard for your application. Of course, a great default configuration has been defined for you here which uses session storage and the Eloquent user provider. All authentication drivers have a user provider. This defines how the users are actually retrieved out of your database or other storage mechanisms used by this application to persist your user's data. Supported: "session" */`

My guard is using a custom model named AdminUser instead of User. If I set up in AuthServiceProvider: Gate::define('viewPulse', function () { return true; });

receive 403 no matter what because I have a different guard for my admins and laravel pulse does not see that I'm logged in.

Also I use laravel nova for my admins.

I think the solution is to make the guard used for laravel pulse configurable in config/pulse.php

Steps To Reproduce:

Create a new guard: 'admins' => [ 'driver' => 'session', 'provider' => 'admins', ],

Create a new provider for your guard: 'admins' => [ 'driver' => 'eloquent', 'model' => App\Models\AdminUser::class, ],

Install laravel nova and change the default guard.

Log in into nova as admin

Add in AuthServiceProvider: Gate::define('viewPulse', function () { return true; });

Try to access laravel pulse. You will receive 403

I tried to configure laravel pulse for another guard than the default one and I got 403.

asked Feb 9, 2024 at 11:23
1
  • Laravel nova is a paid service. I suggest you contact their client support instead of posting your issue here. Commented Feb 18, 2024 at 21:40

1 Answer 1

2

Eventually I gave up on Pulse for now.


The sample code on Laravel Pulse doc is incorrect(?). The $user must be nullable.

(?User $user = null)
Gate::define('viewPulse', function (?User $user = null) {
 if ($user !== null) {
 return $user->isAdmin();
 //return in_array($user->email, [
 // '[email protected]'
 //]);
 }
 
 return false;
});

How I found out about this is, that I checked PulseServiceProvider.php.

protected function registerAuthorization(): void
{
 $this->callAfterResolving(Gate::class, function (Gate $gate, Application $app) {
 $gate->define('viewPulse', fn ($user = null) => $app->environment('local'));
 });
}
answered Feb 18, 2024 at 21:27
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.