I'm writing an app using a multi-tenant architecture. When a new customer signs up they are in the central part of the app. When they submit the registration form, we process payment, set up their tenancy and new database, add the admin user to their users table, log in the admin user and redirect to their dashboard page on their subdomain. When I do this using regular laravel views it works. However, when I'm trying it with inertia I get a cors error in the console. Is there some way I'm not seeing in the docs that explains how to do this?
Workflow overview:
return redirect()->to('acme.example.com/app');This is the cors error I see: Access to XMLHttpRequest at 'http://foo.example.test/app/login' (redirected from 'http://example.test/register') from origin 'http://example.test' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
@drfraker have you set your SESSION_DOMAIN to something like .example.com so your sessions will persist across domains?
Also what did you add in the bootstrap/app.php file to remove the cors errors?
@sicsol Hey Thanks for the response. I added this to the bootstrap/app.php file, just as a way to debug the issue.
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: *');
header('Access-Control-Allow-Headers: *');
Where would one set the SESSION_DOMAIN value? I've never heard of that before.
@drfraker it's in the config/session.php file line 156. You can hard code it there otherwise you can also add it to your .env file as a key and value. Just make sure you add the . before the domain name.
@drfraker Did you get this figured out? This is an annoying problem that really has to do more with the fact that you're making xhr requests than Inertia.js requests. Have you considered simply making these particular signup requests using a full page visit?
@reinink Thanks for replying, that (full page visit) is what we ended up going with.
I face this issue when dealing with a payment processor (mollie-cashier) - is it possible to redirect the user to the payment page if the form doesn't fail? A full page visit isn't pretty if the form fails for example... 馃
Another option here is to return a 409 response with the X-Inertia-Location header set. Here is an example of this: https://github.com/inertiajs/inertia-laravel/issues/57#issuecomment-570581851
Another option here is to return a 409 response with the
X-Inertia-Locationheader set. Here is an example of this: inertiajs/inertia-laravel#57 (comment)
Hi, i don't understand how i can use this to redirect to another page, can you explain to me please?
Hi @kadusalles 馃憢 ,
All you need to do is either use an inertia link, a form request method (such as post, patch etc.), or one of the manual request methods to make a request to your back-end.
Then, on the back-end itself, make sure that the response to that request is what @reinink described in his comment. Once Inertia that response, it should automatically redirect the browser to the location you specified in the X-Inertia-Location header.
Hope this helps!
Redirecting to external sites server-side, from within an Inertia request, is now possible using the new Inertia "location" method:
// Laravel
return Inertia::location('https://www.google.com');
And this is coming to the Ruby adapter shortly (https://github.com/inertiajs/inertia-rails/pull/48).
inertia_location('http://google.com')
Most helpful comment
Redirecting to external sites server-side, from within an Inertia request, is now possible using the new Inertia "location" method:
And this is coming to the Ruby adapter shortly (https://github.com/inertiajs/inertia-rails/pull/48).
More in the docs here and on Twitter here.