This problem is not only on domains but if you also try to login from a different page rather rather the siteurl. You will have this problem.
For example at at https://www.example.com/blog if you log in from here https://www.example.com/blog/wp-login.php there is no problem but if you try at https://www.example.com where the action of this page is https://www.example.com/blog/wp-login.php you will have this problem. I have done the same on my site.
I do not know if you are logging in within the same wp-login.php(directurl) or you have set it as an action to your custom login page like i have done.