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

BindingResolutionException #6

Open
podluzhnyi opened this issue Aug 7, 2017 · 7 comments
Open

BindingResolutionException #6

podluzhnyi opened this issue Aug 7, 2017 · 7 comments

Comments

@podluzhnyi
Copy link

After installation strictly according to the instructions, I have a exception:

Unresolvable dependency resolving [Parameter #0 [ $app ]] in class Codecasts\Auth\JWT\Auth\Guard in Container.php (line 910)

Laravel 5.4.28

I did:

  1. composer require codecasts/laravel-jwt
  2. added service provider Codecasts\Auth\JWT\ServiceProvider::class
  3. published vendor files
  4. generated and added secret to .env
  5. changed driver in api guards to 'jwt'
@pedrogaldino
Copy link

Same here

@hernandev
Copy link
Member

@podluzhnyi @pedrogaldino gonna check it right now

@hernandev
Copy link
Member

@pedrogaldino @pedrogaldino can you explain better where are you triggering this?

The Guard instance should be registered on the laravel and it's not instantiable with resolve since it needs some parameters.

the other guards, default ones are the same

@phillip-elm
Copy link

@podluzhnyi @pedrogaldino @hernandev - did you guys ever find the cause of this? I'm experiencing this exact same issue on Laravel 5.6 / PHP 7.2.

@phillip-elm
Copy link

Just came back from running some errands - took a fresh look at this, I think I figure out what @hernandev meant - this error went away in my code when I stopped trying to have the Guard DI'd into my controller and instead used the Auth facade.

Example:

// This won't even run - the DI will fail. This is adapted from the current README.md.
public function refreshToken(Guard $auth, Request $request)
{
  $token = $auth->refresh();
  return response()->json(compact('token'));
}

Instead, running the following works:

public function refreshToken(Request $request)
{
  $token = \Auth::refresh();
  return response()->json(compact('token'));
}

Once I switched to the latter method, all my tests passed. As such, we probably want to update the README. I'll submit a PR.

@Anticom
Copy link

Anticom commented Nov 23, 2018

I'm rather new to laravel but this looks kind of fishy to me:

// creates a new guard instance passing a provider and a token manager
$guard = new Guard($app, $name, $userProvider, $tokenManager);
// set a event dispatcher on the guard.
$guard->setDispatcher(resolve(Dispatcher::class));
// returns the guard instance.
return new Guard($app, $name, $userProvider, $tokenManager);

Is there any reason a fresh guard is returned and not $guard ?

@jonagoldman
Copy link
Contributor

jonagoldman commented Nov 23, 2018

@Anticom I have already fixed this in PR #45.
@hernandev returning a new instance of the guard resulted in the Auth events not being fired (bug),
I fixed that in my PR, but now because Laravel 5.7 changed the events constructor, the package need to be updated for 5.7 also.

This means the next release of the package will be for >= 5.7 only

@Anticom Anticom mentioned this issue Nov 27, 2018
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

6 participants