laravel / fortify

Backend controllers and scaffolding for Laravel authentication.

Home Page:https://laravel.com/docs/fortify

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError when auth guard driver is token-based

sentisso opened this issue · comments

  • Fortify Version: 1.7
  • Laravel Version: 8.45.1
  • PHP Version: 8.0.7
  • Database Driver & Version: MariaDB 10.4.19

Description:

When guard is set to "api" in the config/fortify.php file and any token-based authentication (token, sanctum...) is used in the project (driver is set to "sanctum" or "token" inside the config/auth.php file), then the application throws a TypeError:

Laravel\Fortify\Http\Controllers\AuthenticatedSessionController::__construct(): Argument #1 ($guard) must be of type Illuminate\Contracts\Auth\StatefulGuard, Illuminate\Auth\RequestGuard given

at \vendor\laravel\fortify\src\Http\Controllers\AuthenticatedSessionController.php:35

When guard is set to "web" again (whose driver is "session" inside the config/auth.php file), then the error is resolved.

This is probably intended? Because I read here on stackoverflow that Fortify was not made for token-based authentication.
Conclusion? Fortify won't work with token-based authentication?

Note: I reported this issue here just in case other people had the same error so they could find the answer here.

Steps To Reproduce:

  1. set "api" in the guard attribute inside config/fortify.php
  2. set the API driver (guards -> api -> driver) inside config/auth.php to any token-based authentication (token, sanctum...)
  3. clear the config cache (php artisan config:cache)
  4. and list the app routes (php artisan route:list)

Yes this is indeed intended. If you feel the docs can be more clear here we're welcoming PR's. Thanks!