I had a similar problem and after many tests I found out there was nothing wrong with the code, I deleted the user’s cookies for google and it ran as expected.