inertiajs / inertia

Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
https://inertiajs.com
MIT License
6.3k stars 423 forks source link

add hidden '_method' field to data if http method is not 'get' or 'post' #1926

Closed YakutD closed 1 month ago

YakutD commented 2 months ago

When submitting a form using methods other than GET and POST, browser redirect errors may occur. For example, if you have a secure DELETE route and you are logged out, the browser will redirect you to the authentication page via DELETE method. Having _method in data solves this problem. Also, I leave the option to override this property in the transform method.

RobertBoes commented 2 months ago

Inertia would already convert those redirect responses to a 303 response (https://inertiajs.com/redirects#303-response-code), which would instruct the browser to perform the follow-up request using GET.

YakutD commented 2 months ago

Inertia would already convert those redirect responses to a 303 response (https://inertiajs.com/redirects#303-response-code), which would instruct the browser to perform the follow-up request using GET.

What version of the adapter made this possible?

RobertBoes commented 2 months ago

That behaviour has been in the Laravel adapter since the first released version; https://github.com/inertiajs/inertia-laravel/blob/v0.1.0/src/Middleware.php#L28

YakutD commented 2 months ago

That behaviour has been in the Laravel adapter since the first released version; https://github.com/inertiajs/inertia-laravel/blob/v0.1.0/src/Middleware.php#L28

When I encountered this problem I was working on a project with the adapter "inertiajs/inertia-laravel": "^0.6.8". And I have to use _method in the form.

RobertBoes commented 2 months ago

When I encountered this problem I was working on a project with the adapter "inertiajs/inertia-laravel": "^0.6.8". And I have to use _method in the form.

Then the issue probably lies somewhere else, as Inertia would already take care of it when the middleware is applied

YakutD commented 2 months ago

When I encountered this problem I was working on a project with the adapter "inertiajs/inertia-laravel": "^0.6.8". And I have to use _method in the form.

Then the issue probably lies somewhere else, as Inertia would already take care of it when the middleware is applied

Are you sure that the request even gets into this middleware if the redirect is initiated by the exception handler?

pedroborges commented 1 month ago

I'm closing this PR since there's no issue with Inertia.js. @YakutD use Discussions if you still need help debugging this problem on your project.