Loging on a cached page in an ESI component redirects on /_internal/secure/…/none.html

StackOverflow https://stackoverflow.com/questions/11815973

  •  24-06-2021
  •  | 
  •  

I've just setup varnish and i've done some tests on port 8080 before switching in production.

I've noticed that if i'm on a cached page :

/**
 * @Cache(smaxage="10800")
 * @Route("/{_locale}/", name="homepage2", requirements={"_locale" = "en|fr"})
 * @Template()
 */
public function indexAction()
{
    return array();
}

And I try to login (not using external services, but with normal login) via the component included via an ESI

    {% render "GamerCertifiedHomeBundle:Home:login" with {}, { 'standalone': true } %}

It ends up redirecting me on a page with no style and no head with the url ...:8080/_internal/secure/MyBundleHomeBundle:Home:login/none.html

Step1 Screenshot / Step2 Screenshot

If I go back on the homepage, i'm logged in.

How can I avoid that please ?

EDIT :

有帮助吗?

解决方案

After analyzing the problem in the chat I found that _target_path for security successful redirect is generated in form in the next way:

<input type="hidden" name="_target_path" value="{{ app.request.uri }}" />

And since this part is rendered with standalone view - it has specific uri (with _internal prefix).

You can avoid this by applying changed logic for your app.request.uri injection.

  1. Pass it to controller:

     {% render yourAction with {'uri': app.request.uri}, {'standalone': true} %}
    
  2. In your controller just pass it to your view

     public function yourAction ($uri)
     {
         ...
         return array('uri' => $uri);
     }
    
  3. Use it in your template

      <input type="hidden" name="_target_path" value="{{ uri }}" />
    

Enjoiy! ;)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top