-
Notifications
You must be signed in to change notification settings - Fork 133
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
fix: change hardcoded user entity with declared return type #1105
Conversation
If a dev extends the UserModel and changed |
Yes that what i mean .. i want customize the User entity, but still extend Shield User entity base class .. before i change the code, if i use email in credential fetch its return the Hardcoded User entity base class instead my User entity class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail if you changed the return type to array
, right?
Based on method type, yes ...because it must return User class .. its no problem to change the returntype but still extend the base user entity class |
@paulbalandan What do you want? |
Let me rephrase: For the longest time, it has been What I am saying is since |
No. If a dev puts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to not have seen the comments earlier and dragging this along.
I am well aware that it will throw a TypeError
if you put other return types there. I even put that remark in my comment. I am just saying that we must be at least prudent in checking the value of $returnType
before instantiating the value. I want to see something along the lines of:
if (! is_a($this->returnType, User::class, true) {
throw new \LogicException('Return type must be a subclass of CodeIgniter\Shield\Entities\User.');
}
As an end user who may be new to Shield, for example, I don't want to be greeted by a TypeError
with message "Return value of fake must return User but returns other class."when faking data. I think it will be a better developer experience if the thrown exception is more informational of the requirement.
I hope I made myself clear.
Yeah that good to implement error message .. honestly, the real purpose of my PR is for use string in user id to implement uuid wkwk (i don't know you notice that or not, i just say it so you can understand it and maybe have best solution for my real problem), because the logic working before, in authentication flow, if use an email-password combination, the return value is hardcoded User entity, and there was an integer id and i don't choose to change or deleted that because i think that not the best solution .. in final authentication of email-password is badly returning only one integer value in uuid cases (9), and all uuid in my case was 9 in first character for all user, so don't care i logged as with email-password, is always returning the first row User in database .. that my real problem bro .. so i think, one of thousand solution is to customize the User entity and change the logic to returning entity that we was define .. in faker method is just an addition, not the real problem .. But yeah, overall is good to implement your advice too .. But, maybe you have the other solution for my real problem, i'm very happy to hear that for long time i wait the PR was confirm .. |
@paulbalandan I don't know how useful that error message would be. Changing the error message that way is fine. |
@MrFrost-Nv27 Line 30 in db10ec1
If you cannot use a string, it is another bug. By the way, what do you mean by "wkwk"? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
In base User entity that was a cast in id with "?integer" so it cant be string, i think i just customize that in my side "wkwk" is just "a laugh in chat" in my country |
@MrFrost-Nv27 Oh, you are correct. Because of #336 |
Yeah, so i think i just want customize the User Entity in my side, not in base side .. and ensure my customize entities work in base flow .. |
Please sign all your commits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes!
Based on your requirement to use UUIDs in $id, I think extending User would be the best solution, to say the least.
@MrFrost-Nv27 Thank you! |
Description
Fixes #1103
Checklist: