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

redirectToRoute triggers a 403 error #10

Closed
fbnlsr opened this issue Jul 21, 2024 · 2 comments · Fixed by #11
Closed

redirectToRoute triggers a 403 error #10

fbnlsr opened this issue Jul 21, 2024 · 2 comments · Fixed by #11
Assignees
Labels
bug Something isn't working

Comments

@fbnlsr
Copy link

fbnlsr commented Jul 21, 2024

I've been battling this issue for days but I can't find a solution for the life of me.

When using $this->redirectToRoute() inside a controller, it triggers an unexpected 403 error making inertia pop up a modal stating "Something went wrong with Inertia!"

Example controller:

<?php

namespace App\Controller;

use Rompetomp\InertiaBundle\Architecture\InertiaInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

class BaseController extends AbstractController
{

    public function __construct(private InertiaInterface $inertia)
    {}

    #[Route('/', name: 'app_home')]
    public function index(): Response
    {
        return $this->redirectToRoute('app_about');
    }

    #[Route('/about', name: 'app_about')]
    public function about(): Response
    {
        return $this->inertia->render('AboutView');
    }

}

The problem only arises when using Link components. When a user goes to / with their browser directly, the redirection is properly interpreted and the correct page is called.

I tried using the Security bundle, as well as with a barebone install, no luck.

I can't figure out if it's an Inertia issue or if the problem comes from the Symfony adapter.

@SkipTheDragon
Copy link
Owner

Hi, looks like you encountered the same problem as #8. You can disable CSRF for now in your inertia.yaml.

inertia:
  # The rest of your configuration here.....
  csrf:
    enabled: false

@SkipTheDragon SkipTheDragon self-assigned this Jul 27, 2024
@SkipTheDragon SkipTheDragon added the bug Something isn't working label Jul 27, 2024
@fbnlsr
Copy link
Author

fbnlsr commented Jul 28, 2024

@SkipTheDragon yup, that was it. I also confirm that updating the bundle to 1.1.2 fixed the issue without having to disable CSRF inside the config.

Thanks a lot for your work! <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants