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

Allow ResponseFactory location to be called with a redirect response #302

Merged
merged 3 commits into from
Dec 2, 2021

Conversation

rojtjo
Copy link
Contributor

@rojtjo rojtjo commented Sep 19, 2021

This change allows the Inertia::location() method to accept a RedirectResponse.

In an app I'm developing using multiple subdomains I ran into the issue that I needed an external redirect after the authentication. Since I want to keep using the redirect()->intended() feature it feels natural to just pass in the whole RedirectResponse in the location method instead of manually getting the target url from the redirect.

Usage example:

// Some controller action

return Inertia::location(
    redirect()->intended(RouteServiceProvider::HOME)
);

Please note that I'm using Symfony's RedirectResponse since Laravel's implementation just extends it.

Let me know what you think!

@RobertBoes
Copy link
Contributor

Another really useful benefit of this would be packages like Socialite. Currently you'll have to do something like the following to make this work:

Route::get('/auth/github', function () {
  return Inertia::location(
    Socialite::driver('github')->redirect()->getTargetUrl()
  );
});

Allowing a RedirectResponse cleans this up nicely and makes the DX a lot better imo.

@claudiodekker
Copy link
Member

@rojtjo Correct me if I'm wrong, but my understanding is that you're redirecting to a non-inertia page in your example, right?

@rojtjo
Copy link
Contributor Author

rojtjo commented Dec 1, 2021

Yes, you are correct. It's only purpose is to save some keystrokes 😅

@RobertBoes
Copy link
Contributor

@claudiodekker in the PR he mentioned he's using Inertia on multiple subdomains, but inertia doesn't work cross-domain (mostly because of the usage of the History API), so you'll have to force a visit to the new subdomain. So it's not only useful for non-Inertia pages, but also to go to another domain that does render an Inertia view

@claudiodekker claudiodekker merged commit b96b552 into inertiajs:master Dec 2, 2021
@claudiodekker
Copy link
Member

Thanks a lot, @rojtjo!

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

Successfully merging this pull request may close these issues.

3 participants