api: Type error: Argument 2 passed to Dingo\Api\Auth\Provider\OAuth2::authenticate() must be an instance of Dingo\Api\Routing\Route, null given

Type error: Argument 2 passed to Dingo\Api\Auth\Provider\OAuth2::authenticate() must be an instance of Dingo\Api\Routing\Route, null given

Get this error when running php artisan clear-compiled

Only seen after updating past e842d8c5245ce2ef9f4384409ae8a775d04b2a38 in dev-master. Prior to this commit everything was working.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 24 (8 by maintainers)

Most upvoted comments

same issue, after running composer update i am getting this, running php 7 and Laravel 5.1

Hi!

I’m having the same error message in a different context: Type error: Argument 2 passed to Dingo\Api\Auth\Provider\OAuth2::authenticate() must be an instance of Dingo\Api\Routing\Route, null given

The error only happens when running tests (phpunit). In a transformer I do:

<?php
namespace App\Api\Transformers;

use League\Fractal\TransformerAbstract;
use App\Thing;

class MyTransformer extends TransformerAbstract
{
    public function transform(Thing $thing)
    {
        $apiUser = app('Dingo\Api\Auth\Auth')->user();

The instruction app('Dingo\Api\Auth\Auth')->user(); triggers the error.

So I tried with helpers (as you mentionned above) :

<?php
namespace App\Api\Transformers;

use League\Fractal\TransformerAbstract;
use Dingo\Api\Routing\Helpers;
use App\Thing;

class MyTransformer extends TransformerAbstract
{
    use Helpers;

    public function transform(Thing $thing)
    {
        $apiUser = $this->user;

And the instruction $this->user; still triggers the error.

Do you have any advices ?

More informations:

  • It only happends in tests
  • This call to transformer is made in the setUp function of the tests (and is executed after a laravel event is triggered)
  • It appeared after a composer install
  • Tests are still passing on my other computer, I tried to composer install there, but didn’t succeed to reproduce the error.

It’s not blocking on my side (as tests pass on my main computer) but I guess it could learn me something, and maybe helps you improving dingo 😃

🍑

@murwa calling app('Dingo\Api\Auth\Auth')->user() will try to authenticate the user, and then return the user. (and in our cases trigger an error)

As a workaround I used app('Dingo\Api\Auth\Auth')->user(false) it returns the user without trying to authenticate it.

I guess it’s fine, because with dingo the authentication is done beforehand, in a route middleware.