codeigniter4 / shield

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

Bug: Config $userProvider is ignored #592

Closed crysaro closed 1 year ago

crysaro commented 1 year ago

PHP Version

8.1.13

CodeIgniter4 Version

4.2.9

Shield Version

v1.0.0-beta.3

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

8.0.31

Did you customize Shield?

No

What happened?

I created a model and named it UserModel.php and placed it under the /app/Models/ directory. I wanted to use this model for dealing with non auth transaction like saving user first name and last name or displaying users on a list. I was thinking of creating another model to be used for Shield and call it AuthModel.php. I left the default value for the $userProvider in the /app/Config/Auth.php to CodeIgniter\Shield\Models\UserModel;

When the creating a new user using the register page this error occurs:

TypeError
CodeIgniter\Shield\Controllers\RegisterController::getUserProvider(): Return value must be of type CodeIgniter\Shield\Models\UserModel, App\Models\UserModel returned

Steps to Reproduce

Register for a new account

Expected Output

I am not sure if my thinking is correct but I expected Shield to still use the CodeIgniter\Shield\Models\UserModel which is the value of the $userProvider in the config and not the App\Models\UserModel

Anything else?

No response

datamweb commented 1 year ago

I haven't checked this but I'm sure you haven't considered section user-providers. Screenshot 2023-01-10 171106

Please use command php spark shield:model UserModel to create a new model.

If you think you have done the steps correctly, please upload the minimum code so I can check.

datamweb commented 1 year ago

An example of correct operation in case of setting public string $userProvider = \App\Models\UserModel::class;.

demo_appmodel

kenjis commented 1 year ago

This is not a bug. It is the specification of CI4. Read https://codeigniter4.github.io/CodeIgniter4/concepts/factories.html#example

I expected Shield to still use the CodeIgniter\Shield\Models\UserModel which is the value of the $userProvider in the config and not the App\Models\UserModel

You need to use an other name than UserModel for your User Model.

crysaro commented 1 year ago

Thank you for the replies!