Zend certified PHP/Magento developer

X-Magento-Vary Cookie getting lost

As the title says, the X-Magento-Vary cookie isn’t working that well on my website.
Sometimes, whenever a customer logs in, the cookie isn’t created and that makes the user lose the session as soon as he enters another page.

I use Varnish 5, Magento 2.3.3 and nginx (could microcache be a problem?);

Varnish configuration regarding this cookie:

if (req.http.cookie ~ "X-Magento-Vary=") {
        hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "1"));
    }

When I login, if I’ve the cookie, everything will work just fine, however, if I login and the cookie isn’t defined yet, I know that when I load the next page, I’ll lose my session or maybe I didn’t login at all.

How can I solve this? Should I create a custom plugin to make sure the X-Magento-Vary it’s always created?