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

Impossible to configure custom User Repository in 7.0.0-BETA1 #256

Closed
pkivits-litebit opened this issue Feb 9, 2022 · 8 comments · Fixed by #257 or #263
Closed

Impossible to configure custom User Repository in 7.0.0-BETA1 #256

pkivits-litebit opened this issue Feb 9, 2022 · 8 comments · Fixed by #257 or #263
Assignees

Comments

@pkivits-litebit
Copy link
Contributor

pkivits-litebit commented Feb 9, 2022

SDK Version

Other (specify in 'additional context')

PHP Version

PHP 8.0

Composer Version

2.x

What happened?

Expected:

Custom user repository configured in config/auth.php to be used by Auth0\Laravel\Auth\User\Provider.

Actual:

Auth0\Laravel\Auth\User\Provider::__construct(): Argument #1 ($repository) must be of type Auth0\Laravel\Auth\User\Repository, SomeCustomUserRepository given, called in /var/www/html/vendor/auth0/login/src/ServiceProvider.php on line 48

How can we reproduce this issue?

In the config/auth.php setup a custom user repository instead of the one provided by auth0/laravel-auth0.

// 👆 Continued from above, in config/auth.php
'providers' => [
    // 📝 Any additional providers you use should stay here, too.
    'auth0' => [
        'driver' => 'auth0',
        'repository' => SomeCustomUserRepository::class
    ],
],

Additional context

Because the $repository parameter in Auth0\Laravel\Auth\User\Provider is expecting a Auth0\Laravel\Auth\User\Repository type, it is impossible to pass any other type then Auth0\Laravel\Auth\User\Repository to Auth0\Laravel\Auth\User\Provider.

Thus making it impossible to configure a custom User Repository.

@evansims
Copy link
Member

evansims commented Feb 9, 2022

Hi @pkivits-litebit 👋 Thanks for your report. Good catch, we should be expecting an Auth0\Laravel\Contract\Auth\User type there, so your custom provider can implement that interface. I'll prepare a PR to adjust that.

@evansims
Copy link
Member

@pkivits-litebit Merged! If you want to update off main to give it a try right away; otherwise a new beta release should be cut next week.

@JanMisker
Copy link

I am attempting to use a custom repository as well, however even with the change to the contract interface I still run into problems.

The thing is that later on in the flow, for example in the handleTokenExpiration function, there are calls to $user->getAccessTokenExpired()

if ($user->getAccessTokenExpired() === false) {

However, that method does not exist on the Illuminate Authenticatable contract, although it does exist on Auth0\Laravel\Contract\Model\User. So it seems the Repository contract should specify that interface instead?
): \Illuminate\Contracts\Auth\Authenticatable;

@JanMisker
Copy link

And thinking it through... my User model should implement the \Auth0\Laravel\Contract\Model\User interface.
I don't think there is any example yet of using a custom user repository? I want to have a User model stored in the application database.

@evansims
Copy link
Member

Hey @JanMisker 👋 Thanks for your thoughtful feedback! That could be worth considering, let me investigate and get back to you. (I'm on vacation for the next week or so, so apologies in advance if I am delayed in any responses.)

@evansims
Copy link
Member

evansims commented Mar 8, 2022

Hey there 👋 Revisiting this topic, I've iterated on the user provider API to ease use of custom user models. The PR implementing these changes is #264 and will be released as Beta 2 this week for feedback.

@affektde
Copy link

We are testing the latest Beta 2 release right now. Also with a custom user model.

We can successfully authenticate our users for now and auth()->user() is holding our Eloquent User.

Thank you for those new commits @sheggi @evansims <3

@evansims
Copy link
Member

Delighted to hear it, @affektde 👍 If you see any room for improvement we can iterate on with this side of things before the full release, don't hesitate to let me know

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.