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

Extension to AuthController fails to "use" custom User entity & model #173

Closed
fefo-p opened this issue Mar 26, 2020 · 8 comments
Closed

Comments

@fefo-p
Copy link
Contributor

fefo-p commented Mar 26, 2020

Maybe it's my ignorance, but I'm trying to extend AuthController so it can use my custom versions of User Entity and Model.

I cannot make it work unless I comment out the lines that use Myth\Auth\Entities\User and Myth\Auth\Entities\UserModel from the original AuthController.

Anyone know how to achieve this?

Link to Images describing the code down here:

Controller
Routes
Model

@fefo-p
Copy link
Contributor Author

fefo-p commented Mar 26, 2020

BTW, I'm using:

  • yesterday's myth-auth code (2020-03-25)
  • CI 4.0.2
  • apache 2.4.41
  • PHP 7.3.8
  • macOS 10.15.4

@agungsugiarto
Copy link
Contributor

Why need to extend if you can publish to your app. Just publish controller, entity, model and do what you want.

php spark auth:publish

@MGatner
Copy link
Collaborator

MGatner commented Mar 26, 2020

I prefer extending as well, because you keep upstream updates without having to re-publish and trying to merge changes.

Your extension won’t work like you are thinking. The “use” statements don’t “extend” as well, you would actually need to implement them. AuthController currently doesn’t use the “model()” function to make this easy, but it would be a quick PR.

@fefo-p
Copy link
Contributor Author

fefo-p commented Mar 26, 2020

Thanks to you both. I'm with MGatner on this one.
I think the quickest way will be for me to copy the entire Controller onto \App\Controllers and change the specified lines. At least until this can get sorted out.
Thanks again!

@fefo-p fefo-p closed this as completed Mar 29, 2020
@MGatner
Copy link
Collaborator

MGatner commented Mar 29, 2020

@fefo-p I would be in favor of leaving this open as a reminder to switch the module to use the model() helper instead, to facilitate extensions.

@fefo-p
Copy link
Contributor Author

fefo-p commented Mar 29, 2020

Sure, no prob.

@lonnieezell
Copy link
Owner

Hey all - I've updated the code to use the model(). Please give it a go in your environments and make sure it works. Trying to get ready to push another beta out and didn't want this to break it without my realizing. Thanks!

@yassinedoghri
Copy link
Contributor

Hi @lonnieezell, I'm currently diving into the code of myth-auth, and must I say I'm learning quite a lot ^^

I have a silly question following this issue, and the refactor you've made by using the model() helper for the UserModel to facilitate extensions (as suggested by @MGatner):

  • wouldn't it be best if all of the instanciated models were so using the model() helper? (to ease any extension for GroupModel, PermissionModel and LoginModel).

I've had a need to overwrite the PermissionModel and UserModel instanciated in the services. So I had to change my App\Config\Services by copy/pasting the authentication and authorization services from myth-auth, so I can replace the models with my own (not sure if it's the right way to do it though).

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

5 participants