Search code examples
firebasefirebase-securityfirebasesimplelogin

Firebase authWithOAuthRedirect() woes


I'm trying to update my angularjs app to support Firebase 1.1 (I was stick with Firebase 1.0.x).
It deprecates firebasesimplelogin, including authentication inside Firebase core.

I have been able to successfully implement authentication using

authWithOAuthPopup("<provider>", function(error, authData) { ... });

It accepts a callback, which is passed authentication data in authData.

On the contrary, I can't undersand how to use

authWithOAuthRedirect("<provider>", function(error) { ... });

Firebase Authentication docs page is very concise... :-(. This is all what is said:

Alternatively [instead of authWithOAuthPopup], you may prompt the user to login with a full browser redirect, and Firebase will automatically restore the session when you return to the originating page

How do I get authData, when Firebase - after redirection - returns to my page?


Solution

  • The authData is available by registering a listener directly on the ref (so before calling authWithOAuthRedirect).

    ref.onAuth(function(authData) { 
        ... 
    } 
    ref.authWithOAuthRedirect("google", function(error) { ... });
    

    See https://www.firebase.com/docs/web/guide/user-auth.html#section-monitoring-authentication