Reputation: 46479
I am trying to write minimalistic mocks fro firebase's auth to satisfy use cases like
facebookSignIn = async () => {
try {
const user = await FacebookLogIn.logIn();
const credential = firebase.auth.FacebookAuthProvider.credential(user.accessToken);
await firebase.auth().signInAndRetrieveDataWithCredential(credential);
} catch (e) {
Alert.alert("Error", e.message);
}
};
I've got this far
const firebase = {
auth: {
onAuthStateChange: callback => {
callback({
user: {
uid: "123",
email: "[email protected]"
}
});
},
FacebookAuthProvider: {
credential: accessToken => ({ param: "1" });
}
}
};
my main concern now is difference when doing
const credential = firebase.auth.FacebookAuthProvider.credential(user.accessToken);
and
await firebase.auth().signInAndRetrieveDataWithCredential(credential);
you can see that auth here is an object and a function at the same time, I'm not entirely sure about how I can mock that :/
Upvotes: 2
Views: 623
Reputation: 2435
In JavaScript functions are objects too. You can simply add the properties you need to it.
const firebase = {
auth: function(){
console.log('foo');
}
};
firebase.auth.bar = 'bar';
firebase.auth();
console.log(firebase.auth.bar);
Upvotes: 3