laravel / fortify

Backend controllers and scaffolding for Laravel authentication.
https://laravel.com/docs/fortify
MIT License
1.62k stars 294 forks source link

All Fortify routes should have names #554

Closed dirkam closed 4 months ago

dirkam commented 4 months ago

As of now, some routes don't have a name assigned.

        Route::get(RoutePath::for('two-factor.recovery-codes', '/user/two-factor-recovery-codes'), [RecoveryCodeController::class, 'index'])
            ->middleware($twoFactorMiddleware)
            ->name('two-factor.recovery-codes');

But the POST route doesn't have a name:

        Route::post(RoutePath::for('two-factor.recovery-codes', '/user/two-factor-recovery-codes'), [RecoveryCodeController::class, 'store'])
            ->middleware($twoFactorMiddleware);

This way one can only check for these routes in middlewares with $request->getPathInfo() and such, but it can be dynamic, for instance in the case of a multi-tenant application. With named routes, one can just check Route::currentRouteName() or such.

Or am I missing something to be able to still use route name checks for these routes?

driesvints commented 4 months ago

It's the exact same route. The HTTP method doesn't matter. You can reference both with this name.

dirkam commented 4 months ago

Thanks for the quick response @driesvints! This is weird as it seems that Route::currentRouteName() returns null in the case of the POST route. I've just tested it with the login route. When the login screen is shown (GET), it returns login. When the login is submitted the POST route returns null.

Am I doing something wrong?

driesvints commented 4 months ago

Okay, I can see that's a problem for you. In this case currentRouteName won't work.

Seeing https://github.com/laravel/fortify/pull/550 being declined I think it's highly unlikely we'll take any action here soon. You could try an attempt to submit a PR to add remaining route names but PR's in the past have been declined. If you do, please make sure to explicitly state the issue with the currentRouteName method to build your case for it.