[11.x] Route [login] not defined due to missing auth routes registration
- Laravel Version: 11.0.3
- Nova Version: 4.33.0
- PHP Version: 8.3.3
- Database Driver & Version: sqlite
- Operating System and Version: macOS Sonoma Version 14.4
- Browser type and version: Google Chrome Version 122.0.6261.129 (Official Build) (arm64)
Description:
A new installation of Laravel 11 and Nova 4 does not redirect the nova.path to the login page. The login url itself works.
Detailed steps to reproduce the issue on a fresh Nova installation:
- Install Laravel 11:
laravel new awesomeness - Install Nova 4:
cd awesomeness&& composer require laravel/nova php artisan serve- Navigate to: http://127.0.0.1:8000/nova
Expected behaviour
Redirect to: http://127.0.0.1:8000/nova/login
Current response
Symfony\Component\Routing\Exception\RouteNotFoundException
Route [login] not defined.
Possible "Fix"
Add auth routes to routes/web.php
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', static function () {
return view('welcome');
});
Auth::routes();
Unfortunately, I didn't get to the root cause, or perhaps I overlooked a configuration?
Getting the same issue with clean Laravel 11 install
I've just encountered the same issue.
- Fresh instal of Laravel 11 and Nova 4
- Local development using Laravel Herd
- Running PHP 8.2
I've also added the Auth::routes(); in routes/web.php which temporary fixed it for now.
I solved in this way on my bootstrap/app.php:
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Foundation\Http\Middleware\TrimStrings;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->append(TrimStrings::class);
$middleware->redirectGuestsTo(fn () => route('nova.pages.login'));
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
I don't have this problem because I use a different authentication system, but if the link works cant you just update the config?
I use the below config in /config/nova.php
'routes' => [
'login' => '/auth/redirect',
'logout' => '/auth/logout'
]
So maybe you could do something like:
'routes' => [
'login' => '/nova/login',
'logout' => '/nova/logout'
]
Don't know if it works, but maybe this helps finding the problem.
@crynobone should we make PR to nova-docs?
Having this problem too. The nova/login route is there when I run artisan route:list. Seems like a Nova bug more than a documentation issue? I feel like out of the box Nova should be able to handle redirecting unauthenticated users from /nova to /nova/login. Also raised here https://github.com/laravel/framework/issues/51113
There's scenarios where:
- application has a "frontend" login for normal user.
- application and Nova use separate auth guard.
For above cases, Nova shouldn't be the default redirected page for login.
Fair, it's just strange that setting up Nova on a 10.x Laravel project does the redirect for you and on a 11.x Laravel project it doesn't.
There's scenarios where:
- application has a "frontend" login for normal user.
- application and Nova use separate auth guard.
For above cases, Nova shouldn't be the default redirected page for login.
Yes... Here is how I use it now. So I make current redirect if it's only nova request.
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Foundation\Http\Middleware\TrimStrings;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->redirectGuestsTo(function (Request $request) {
$isNovaPath = $request->is(str_replace(search: '/', replace: '', subject: config('nova.path')));
return $isNovaPath ? route('nova.pages.login') : null;
});
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
There's a new prompt in nova:install command to solve this. For existing application above code work or you can update App\Providers\NovaServiceProvider:
/**
* Register the Nova routes.
*
* @return void
*/
protected function routes()
{
Nova::routes()
- ->withAuthenticationRoutes()
+ ->withAuthenticationRoutes(default: true)
->withPasswordResetRoutes()
->register();
}
Had the same problem with a FRESH install. Why do I have to solve this by searching and finding this here?