Cookies are not working on second app launch

I’m using capacitor with authentication through cookies, I had to change some code in order it to work. The problem is that first launch when the cookie is null, everthing is working. On the second launch, the Set-Cooke cannot set the cookie on the webView because of “this attempt to set a cookie was blocked due to user preferences”.

Any Idea why?

This are my changes

public void onStart(){
    super.onStart();

    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.flush();
    WebView webView = bridge.getWebView();

    cookieManager.setAcceptThirdPartyCookies(webView, true);
  }
}