Reputation: 57
I'm using When I try to log in or create a new user I get the following error messages
Error in firebase.createUser: TypeError: Cannot read property 'FirebaseAuth' of undefined
Error in firebase.login: TypeError: Cannot read property 'FirebaseAuth' of undefined
I have firebase.init running in my app.component.ts file.
I have been following the steps in the firebase nativescript plugin documentation for implementation.
Here's where the firebase.createUser method is called
register(user) {
return new Promise((resolve, reject) => {
console.log(user);
firebase.createUser({
email: user.email,
password: user.password
}).then(
function (user) {
alert("User created, email: " + user.email)
},
function (errorMessage) {
alert("Error: " + errorMessage)
}
);
});
}
Here's where the firebase.login method is called
login(user) {
return new Promise((resolve, reject) => {
console.log(user);
firebase.login(
{
type: firebase.LoginType.PASSWORD,
passwordOptions: {
email: user.email,
password: user.password
}
})
.then(result => JSON.stringify(result))
.catch(error => console.log(error));
});
}
Here's my firebase.init call
firebase.init({
// Optionally pass in properties for database, authentication and cloud messaging,
// see their respective docs
}).then(
() => {
console.log("firebase.init done");
} ,
error => {
console.log(`firebase.init error: ${error}`);
}
);
var listener = {
onAuthStateChanged: function(data) {
console.log(data.loggedIn ? "Logged in to firebase" : "Logged out from firebase");
if (data.loggedIn) {
console.log("User Info", data.user);
}
},
thisArg: this
};
// add the listener:
firebase.addAuthStatListener(listener);
// stop listening to auth state changes:
firebase.removeAuthStateListener(listener);
// check of already listening to auth state changes
firebase.hasAuthStateListener(listener);
The login and createUser methods should communicate with my firebase project to create a new user or to log in an existing user.
Upvotes: 1
Views: 811
Reputation: 421
For me also having same problem. I'm using nativescript-plugin-firebase version 10.3.3 with nativescript 6.3.0.
nativescript-plugin-firebase plugin team has proposed solution to set "analytics": true in firebase.nativescript.json.
https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/1431#issuecomment-543735961
But for me it didn't work
Upvotes: 0
Reputation: 57
It turns out, this problem is due to my testing my app using nativescript preview as this does not support the nativescript firebase plugin.
Upvotes: 1