Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when assign a String in redirectGuestsTo #50871

Closed
MrJmpl3 opened this issue Mar 31, 2024 · 5 comments
Closed

Crash when assign a String in redirectGuestsTo #50871

MrJmpl3 opened this issue Mar 31, 2024 · 5 comments

Comments

@MrJmpl3
Copy link

MrJmpl3 commented Mar 31, 2024

Laravel Version

11.1.1

PHP Version

8.3

Database Driver & Version

No response

Description

Crash when assign a String in redirectGuestsTo, but the app works when assign a function.

That is rare because in the line https://github.com/laravel/framework/blob/11.x/src/Illuminate/Foundation/Configuration/Middleware.php#L523 is configure to support string and function

Steps To Reproduce

I use Inertia and Redis, you only need assign a string in redirectGuestsTo

->withMiddleware(function (Middleware $middleware) {
        $middleware
            ->redirectGuestsTo(route('auth.login'))
            ->throttleWithRedis()
            ->web(append: [
                HandleInertiaRequests::class,
                AddLinkHeadersForPreloadedAssets::class,
            ]);
    })
@crynobone
Copy link
Member

But this is valid, right? ->redirectGuestsTo(route('auth.login'))

@MrJmpl3
Copy link
Author

MrJmpl3 commented Apr 1, 2024

But this is valid, right? ->redirectGuestsTo(route('auth.login'))

I think is correct, because in the line https://github.com/laravel/framework/blob/11.x/src/Illuminate/Foundation/Configuration/Middleware.php#L523, transform the string to function and the types of $guests are "callable|string"

@crynobone
Copy link
Member

So what's the crash? and actual reproducing step?

@ahinkle
Copy link
Contributor

ahinkle commented Apr 2, 2024

The docs make it pretty clear to use a callback with using routes:

https://laravel.com/docs/11.x/authentication#redirecting-unauthenticated-users

The string is for hardcoded URLs. I think it's not possible because the app hasn't fully booted yet for the route resolver (the reasoning for the required callback), but I am not entirely sure.

@driesvints
Copy link
Member

This can only be a hardcoded path or a callback. Never a named route like in the example above because of the reasons @ahinkle listed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants