Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permissions and Role Disapper(empty) from Model after ~10-14 requests #2693

Open
jihadismail8 opened this issue Jul 10, 2024 · 7 comments
Open

Comments

@jihadismail8
Copy link

jihadismail8 commented Jul 10, 2024

Description

ok guys i been looking for this issue for two days already and can not find the problem i am using laravel 11 with octane (roadrunner) all the latest versions (fresh install) , i got jetstream as well , and spatie permissions with teams ON . so during requesting my user model with permissions and roles , i get the data and everything is good , after around 14 requests in a row , the role and permissions from user Model becomes empty , i tried to use " setPermissionsTeamId('1')" almost everywhere ( routes, in __construct of the controller and in the method of the controller , nothing helped , i tried to flush in octane settings in "OperationTerminated" also did not help , keep notice that in artisan serve mode it works fine , so it seems something with octane is the issue or with this package , if anything , i am trying to upgrade my project from laravel 10 to laravel 11 , which in it i have this package ( version 5.9 ) and older octane and laravel 10 , and it is working fine no issues with it .

Steps To Reproduce

1.clone the repo , then - docker compose build ( sorry for the long build time , all the extentions are needed )
2.docker compose up
3.postman ( post request to (http://0.0.0.0:8081/api/login ) ) get the token , user can be found in seeder RolesAndPermissionsSeeder
4.GET request to (http://0.0.0.0:8081/api/permissions ) not to forget to add Bearer Token in header

Example Application

https://github.com/jihadismail8/OctaneSpatie

Version of spatie/laravel-permission package:

6.9

Version of laravel/framework package:

11

PHP version:

8.3

Database engine and version:

sqlite

OS: Windows/Mac/Linux version:

ubuntu 22

@jihadismail8
Copy link
Author

i tested the API's calls and i tested livewire , on both the issue persists .
you can try livewire as well , go to 0.0.0.0:8081/login , then /dashboard , in dashboard you can click on up right corner( user name) go to Roles page and back for around 14 times , and the permissions with roles will disappear and pages wont become accessible anymore

@parallels999
Copy link
Contributor

parallels999 commented Jul 11, 2024

Hi, I don't use octane, and I wouldn't know how to fix it.
But, feel free to make a PR fixing it

protected function registerOctaneListener(): void
{
if ($this->app->runningInConsole() || ! $this->app['config']->get('octane.listeners')) {
return;
}
$dispatcher = $this->app[Dispatcher::class];
// @phpstan-ignore-next-line
$dispatcher->listen(function (\Laravel\Octane\Contracts\OperationTerminated $event) {
// @phpstan-ignore-next-line
$event->sandbox->make(PermissionRegistrar::class)->setPermissionsTeamId(null);
});
if (! $this->app['config']->get('permission.register_octane_reset_listener')) {
return;
}
// @phpstan-ignore-next-line
$dispatcher->listen(function (\Laravel\Octane\Contracts\OperationTerminated $event) {
// @phpstan-ignore-next-line
$event->sandbox->make(PermissionRegistrar::class)->clearPermissionsCollection();
});
}

@jihadismail8
Copy link
Author

i been trying for two days with no luck )) i tried to ->setPermissionsTeamId(null) and ->clearPermissionsCollection() in octane config listeners but still no luck , same issue . and again this used to work fine on laravel 9 and spatie 5.9

@parallels999
Copy link
Contributor

this used to work fine on laravel 9 and spatie 5.9

You could check what has changed between those versions, maybe the bug is there

@jihadismail8
Copy link
Author

https://github.com/spatie/laravel-permission/compare/671e46e..80a32a1
could not find anything helpful !!!

@jihadismail8
Copy link
Author

ok an update to the issue , when the teams=>false in permission config file is set there is no problem .
so seems octane is losing the team id somewhere and because of it the roles and permissions as well .
any idea how to debug it ? where the app would be losing the team id if in controller inside the method i am setting the id ( setPermissionsTeamId('1');) ?

@parallels999
Copy link
Contributor

parallels999 commented Jul 12, 2024

seems octane is losing the team id somewhere

It seems that you did not read my initial comment, I specified where in the code that happened(Also #2545)

It seems that you did not follow the documentation, the middleware is supposed to put the team_id again in each request
laravel-permission/teams-permissions#content-working-with-teams-permissions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants