Max Stride Max Stride - 1 year ago 146
Javascript Question

Firebase Authentication Javascript: setCookie for pending Credential for redirect

I am trying to get the multiples auth to link using

. I grab the error
and use
to pass it through a cookie.

From there, I convert it back to an object by using
, but when I tried to pass the credential object into
, it's giving me an error stating:

firebase.js:74 Uncaught Error: link failed: First argument "credential" must be a valid credential

Do I have to convert JSON object into a Firebase object in order to pass it in the credential? What the object originally looks like:

Ef {accessToken: "EAAQmrlAUQpEBAL4oiPWEJy.......", provider: ""}

What the object looks like after converting back to JSON from
cookie ('string')

Object {accessToken: "EAAQmrlAUQpEBAL4oiPWEJy.......", provider: ""}

Answer Source

You should be careful to remove cached accessToken and secret after you are done with them.

The parsed JSON is possibly not a valid firebase object to link the pending credentials. You must pass it into the firebase auth provider object first before linking.

// Read cookie
var pendingCred = document.cookie;

// Parse
var pendingCredObj = JSON.parse(pendingCred);

// Delete cookie
document.cookie ="pendingCred="pendingCred", null, 0";

// Link with appropriate auth provider object
if (pendingCredObj.provider == ""){
    var pendingCredObjProv = firebase.auth.TwitterAuthProvider.credential(pendingCredObj.accessToken, pendingCredObj.secret);
} else if (pendingCredObj.provider == ""){
    var pendingCredObjProv = firebase.auth.FacebookAuthProvider.credential(pendingCredObj);
} else if (pendingCredObj.provider == ""){
    var pendingCredObjProv = firebase.auth.GoogleAuthProvider.credential(pendingCredObj);
} else if (pendingCredObj.provider == "password"){
    var pendingCredObjProv = firebase.auth.EmailAuthProvider.credential(pendingCredObj);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download