I was struggling with this issue for a few days. Not sure if my Firebase setting was wrong or if my code was wrong.
The it was resolved by the following steps.
In the Credentials -> OAuth 2.0 Client IDs, find the Web Application you are using, get in and add https://yourcustomdomain/__/auth/handler in the Authorized redirect URIs.
In your firebase auth Config, change authDomain to your custom domain.
*** Add the following to the nginx.
location /__/auth { proxy_pass https://.firebaseapp.com; }
Without the step 3, you will get a 404 on https://yourcustomdomain/__/auth/handler.
For the solution, you may refer to the following web site. I am not sure if my problem was caused by the browsers that block third-party cookies. But the solution saved my life!