Firebase Messaging getToken() throws: Cannot read property 'buffer' of undefined - firebase

I get the error "Cannot read property 'buffer' of undefined" if I call the method getToken(), but only on my work notebook.
On my pesonal PC it is working.
Here is my code in the web app created via TypeScript:
this.messaging.requestPermission()
.then(() => {
console.log('Notification permission granted!');
return me.messaging.getToken(); ==> Here I get the error on my work notebook!
})
.then(messagingToken=> {
me.updateMessagingToken(messagingToken);
})
.catch((err) => {
console.log('Unable to get permission to notify.', err);
me.openSnackBar("Unable to get permission to notify!" + err);
})

It seems to me that you may have cached older version of your app. Have you tried (1) clearing the cache, (2) using private mode, (3) using another browser?

Related

Cloud firestore unable to deploy delete user function from project

Error: "Cloud Fire Error: functions predeploy error: Command terminated with non-zero exit code 1"
I have a view all users screen in my application. On this screen, I have access to both email and uID. I need to build functionality that I can click a delete user button on the users tile. This should then delete the user from firebase authentication and the users collection in firebase. I seen from other posts that the best way for this would be to create a cloud function which I have tried from firestore documentation. I am getting the below error. The code I am trying is from firestore documentation and is as follows:
getAuth()
.deleteUser(uid)
.then(() => {
console.log('Successfully deleted user');
})
.catch((error) => {
console.log('Error deleting user:', error);
});
Attaching documentation link - https://firebase.google.com/docs/auth/admin/manage-users#node.js_7
Any advice is much appreciated.
This may happen because:
You don't have eslint installed. This could happen if at the time you ran firebase init functions you answered no when prompted Do you want to use ESLint to catch probable bugs and enforce style? and/or you answered no when prompted to install dependencies. If that's the case reinitialize the environment to get it installed.
You're missing the eslint package in your package.js file. To check/fix this open it up and look if you have something in the lines of:
"devDependencies": {
"eslint": "^4.12.0",
"eslint-plugin-promise": "^3.6.0"
},
As stated by #Werner7, that is also a possible solution.
Edit upon reading your question again:
This isn't a direct answer to your question but just a few things to note...
You essentially have 2 options here - deleting the user form the front end or firebase functions - each is slightly different.
Front end - You need to pass the user object into deleteUser() not the user's uid, and vice versa passing in the uid.
Firebase function example:
return admin.auth().getUserByEmail(data.email).then(user => {
return admin.auth().deleteUser(user.uid);
}).then(() => {
return {
massage: `Success, ${data.email} has been deleted.`
}
}).catch(err => {
return err;
});
Front end example:
import { getAuth, deleteUser } from "firebase/auth";
const auth = getAuth();
const user = auth.getUser(uid)
deleteUser(user).then(() => {
// User deleted.
}).catch((error) => {
// An error ocurred
// ...
});
https://firebase.google.com/docs/auth/web/manage-users#delete_a_user

How to fix the error : your application id may be incorrect. If the error persists, contact support#algolia.com

I want to send cloud firestore data to algolia to enable full-text search. Firebase cloud function log is showing an error about application id. I am not able to understand this error and how to fix this.
name: 'RetryError',
message: 'Unreachable hosts - your application id may be incorrect. If the error persists, contact support#algolia.com.'
This is my index.js file
exports.addFirestoreDataToAlgolia =
functions.https.onRequest((req, res) => {
var arr = [];
admin.firestore().collection("tags").get()
.then((docs) => {
docs.forEach((doc) => {
let user = doc.data();
user.objectID = doc.id;
arr.push(user);
})
const client = algoliasearch(ALGOLIA_ID, ALGOLIA_ADMIN_KEY);
const index = client.initIndex(ALGOLIA_INDEX_NAME);
return index.saveObjects(arr, (err, content) => {
if (err) {
res.status(500);
}
else {
res.status(200).send(content);
}
})
})
.catch( err => {
console.log(err);
})
})
Outbound requests (outside of Google services) can only be made from functions on a paid plan (https://firebase.google.com/pricing).
Reason for the wrong appID error is that the Algolia is trying to resolve a dns using your appID, which fails. See https://github.com/algolia/algoliasearch-client-javascript/issues/587#issuecomment-407397688
You have to move off of the free Spark plan in order to call out to Algolia from your function..
I also got this error with NextJS, it was working fine with react but then when I moved to NextJs I got the error.
Turns out it was my .env variables that were not being passed correctly to the client/browser. Renaming the variables from REACT_APP_<variable name> to NEXT_PUBLIC_<variable name> to make them available to the browser as per the NextJs documentation fixed the issue.
NEXT_PUBLIC_ALGOLIA_APP_ID=xxxxxx
NEXT_PUBLIC_ALGOLIA_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
NEXT_PUBLIC_ALGOLIA_ADMIN_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxx

task.ref.getDownloadURL() throws "storage/object-not-found" error

When I try to upload files to the storage server, it uploads fine. But when I subscribe to the snapshot changes to get the download URL, it throws an error.
Here is my code:
const fileForUpload = this.filesForUpload[0];
this.afStorage
.upload(
fileForUpload.path,
fileForUpload.file,
fileForUpload.metadata
)
.snapshotChanges()
.subscribe(task => {
const downloadUrl = task.ref.getDownloadURL(); // throws error!
});
Here's the error message:
Firebase Storage: Object
'reddit/1532105412851_node_js_hexagon-wallpaper-1920x1080.jpg' does
not exist.
Here's a screenshot if you want more details on the error message:
It says reddit/ because I'm recreating reddit.com for practice.
When I look at my storage on firebase, I see the file uploaded fine.
use the call back function
this.storage.ref(path).putString(this.image, 'data_url').then(data => {
//data in this case contains the download ref
console.log(data) //this will help you see the response
});

Realm in React Native - TypeError while not using JS Debugging

I am Currently developing an app in react-native in which I would like to create a Database on the device as well. I found a good library Realm to use as a Database storage in my app but I am having error in running it.
App works fine when I activate Debug JS remotely
Fails and gives error
TypeError: Undefined is not a function (evaluating _iterator3[typeof Symbol === "function"...
when I run it without using Debug JS remotely
I need help in determining the cause of my error
What am I missing here?
My code to handle Realm
let userSchema = {
name : 'User',
primaryKey : 'id',
properties : {
id : {type:'string',indexed:true},
name : 'string',
email : 'string',
password : 'string',
}
}
let realm = new Realm({schema:[userSchema],deleteRealmIfMigrationNeeded:true});
export function getAllUsers(){
try {
let usersObject = realm.objects('User');
let userArray = [];
for(let user of usersObject){
userArray.push(user);
}
return userArray;
} catch (e) {
console.log("Error on creation",e);
}
}

Meteor Account.createUser TypeError: Cannot read property 'accessToken' of undefined

I try to create User Registration. I have install
accounts-base 1.2.2* A user account system
accounts-password 1.1.4* Password support for accounts
On client side :
var userNew = {
password: textPassword,
username: textUserName,
profile: {
address: textAddress
}
};
Accounts.createUser(userNew, function (err) {
if (err) {
alert(err.message);
} else {
Router.go('/');
}
});
But show error :
I20160423-17:47:07.299(7)? Exception while invoking method 'createUser' TypeError: Cannot read property 'accessToken' of undefined
Also i have set on server side :
Accounts.config({
forbidClientAccountCreation : false
});
I done with update & recreate PROJECT. I dont figure whats the problems. but recreate project solved this problems.
Hopelly its helps others

Resources