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

Bad Request (#400) submiting a form on regular response #6

Open
nye opened this issue Oct 15, 2023 · 2 comments
Open

Bad Request (#400) submiting a form on regular response #6

nye opened this issue Oct 15, 2023 · 2 comments

Comments

@nye
Copy link

nye commented Oct 15, 2023

In a controller action if I return a regular respone, regular view with a form, when I submit this form I get a Bad Request (#400) error. I guess this is related to CSRF??

What I'm trying to do is that I don't want to use Inertia in all controllers/actions but use it only in some cases. So I would like to use regular views and forms as usually and be able to "enhance" som controllers using Svelte with Inertia. Is this possible or am I missing something?

@ing-edgar
Copy link

ing-edgar commented Nov 1, 2023

 'components' => [
        'inertia' => [
            'class' => Inertia::class,
        ],
        'request' => [
            'class' => 'tebe\inertia\web\Request',
            'cookieValidationKey' => '<cookie_validation_key>',
            'enableCsrfValidation' => true,
            'enableCsrfCookie' => true,
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
            ]
        ],

Please remember to insert these lines into the appropriate configuration file (either config/web.php or advanced app backend/config/main.php), and replace <cookie_validation_key> with the correct cookie validation key.

@nye
Copy link
Author

nye commented Nov 4, 2023

Yes, and this is when I get the error:

'enableCsrfValidation' => true,
'enableCsrfCookie' => true,

If I set these to false, I get no error, but of course, I'm not using CSFR protection.

What I want is to keep using CSFR, becouse in my app there will be a lot of regular actions (without Inertia) and also some actions with Inertia.

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

No branches or pull requests

2 participants