codeigniter4 / shield

Authentication and Authorization for CodeIgniter 4
https://shield.codeigniter.com
MIT License
351 stars 123 forks source link

Call to a member function getGroups() on null #210

Closed ondequadre closed 2 years ago

ondequadre commented 2 years ago

I point out that when the logout is performed, an error occurs in the development environment with the toolbar active, as shown in the attached image. In production environment or disabling the toolbar the error does not appear.

error

datamweb commented 2 years ago

Hello @ondequadre . This error is due to the fact that in Table auth_groups_users without a group are user registered. Please send the output of the following command for review if you are using version CI4.2. php spark db:table auth_groups_users

ondequadre commented 2 years ago

Hello @datamweb, here the output:

CodeIgniter v4.2.0 Command Line Tool - Server Time: 2022-06-05 21:17:46 UTC+02:00

Data of Table "auth_groups_users":

+----+---------+------------+--------------------+
| id | user_id | group      | created_at         |
+----+---------+------------+--------------------+
| 1  | 1       | superadmin | 2022-06-05 17:4... |
| 2  | 2       | user       | 2022-06-05 19:1... |
+----+---------+------------+--------------------+
kenjis commented 2 years ago

I've checked, but can't reproduce the error.

If you logged out, the following if statement would be false. How did you logout?

https://github.com/codeigniter4/shield/blob/f2160b0eb41b986c56ad225f9375f6d9e18e6433/src/Collectors/Auth.php#L65-L67

datamweb commented 2 years ago

There is a corner of this error. I had the same problem two days ago. I tried to repeat the mistake so I could write a test, but it failed.

kenjis commented 2 years ago

There is a corner of this error.

What do you mean?

datamweb commented 2 years ago

@kenjis after login ,If the first time http://localhost:8080/logout is called, an error is displayed. Then, if http://localhost:8080/logout called again, the user will logout successfully and no error will be displayed.

Step 1 : login

login

step 2 : http://localhost:8080/logout

logoutwhitError

step 3 : http://localhost:8080/logout

logouSu

@ondequadre Do you confirm this?

kenjis commented 2 years ago

@datamweb Please check #211 if it fixes the problem.

ondequadre commented 2 years ago

@datamweb Yes I confirm that is exactly what happens

datamweb commented 2 years ago

@ondequadre This case was resolved #211 . And waiting for merge. Thanks for your report.