Symfony 6 RedirectResponse url with query parameters issue

42 views Asked by At

I'm using Symfony 6. I'm trying to get my user redirected after a successfull login to the same page he was on before requesting login. I store the initial url in the session.

on a twig template there is the login link : {% set login_link = '/spotify/connection?initialUrl=' ~ app.request.requestUri %} <a href={{ login_link }}>

Here is the "onAuthenticationSuccess" method of my custom authenticator class :

    public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
    {

        $session = $request->getSession();
        $initialUrl = $session->get('initialUrl');

        if(null !== $initialUrl)
        {

            return new RedirectResponse($initialUrl);

        }
        return null;
    }

Here's my issue :

I can get my variable $initialUrl to be the url I want (without the domain, with the parameters). But : This line

return new RedirectResponse($initialUrl);

redirects the user to the wrong page, the characters ?= seems to have changed to something like #; so no parameter is recognized

While this line :

return new RedirectResponse('/spotify/player?sessionId' . $sessionId);

Works fine... while obviously I checked and in both cases the string is the same...

Any idea why?

Read documentation, tried researches, finally got that manually making the url works... don't know why

0

There are 0 answers