1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Laravel Passport: TypeError: Argument #2 ($guard) must be of type...

Discussão em 'Outras Linguagens' iniciado por alireza.haraji.dev, Novembro 5, 2024 às 13:52.

  1. I'm encountering an error when using Laravel Passport with Laravel version 10.48.22 and Laravel Passport version 12.3.0.

    Steps to reproduce:


    1. I moved the predefined application routes to a separate file api.php following the Laravel documentation.


    2. I set the guard in the config/passport.php file to 'api'.

    Error Message:

    TypeError: Laravel\Passport\Http\Controllers\AuthorizationController::__construct(): Argument #2 ($guard) must be of type Illuminate\Contracts\Auth\StatefulGuard, Laravel\Passport\Guards\TokenGuard given in file C:\PHP\rest-api-backend\vendor\laravel\passport\src\Http\Controllers\AuthorizationController.php on line 52


    • I verified that the api guard is defined correctly in config/auth.php.


    • I reviewed the Laravel Passport documentation for any additional configuration needed for the api guard.


    • I searched Stack Overflow for similar issues but couldn't find a solution.

    Possible Causes:


    • There might be a mismatch between the expected guard type by AuthorizationController and the provided TokenGuard.


    • There might be a configuration issue requiring additional steps to enable the api guard with Laravel Passport.

    What I Need Help With:


    • Understanding why AuthorizationController expects a StatefulGuard instead of the provided TokenGuard.


    • Finding a way to resolve the type mismatch and make the api guard work with Laravel Passport.

    Additional Information:


    • Relevant code snippets:

      • config/passport.php (guard configuration)


      • config/auth.php (api guard definition)


      • api.php (relevant route definitions)

    • I've commented out the pre-defined Laravel Passport routes in api.php.

    Thank you for any help or suggestions you can provide!

    Continue reading...

Compartilhe esta Página