Meteor: Uncaught Error: Must be attached (delete function) - javascript

I have an error in the console every time I'm deleting an item (List) in my Meteor application.
The error in the console is:
domrange.js:337 Uncaught Error: Must be attached
Here is the function, I can't understand where come from this error:
Lists.js
Meteor.methods({
'lists.remove'(listId) {
check(listId, String);
const list = Lists.findOne(listId);
if (list.owner !== this.userId) {
throw new Meteor.Error('not-authorized');
}
Tasks.remove({"listId": listId});
Lists.remove(listId);
},
All is working properly in the application but do you know where this error can come from ?
Ps: I'm using Blaze if it can help
thanks

It seems I found the solution adding a Meteor.isServer or better if (!this.isSimulation) (#MasterAM solution):
'lists.remove'(listId) {
check(listId, String);
const list = Lists.findOne(listId);
if (list.owner !== this.userId) {
throw new Meteor.Error('not-authorized');
}
if (!this.isSimulation) {
Tasks.remove({"listId": listId});
Lists.remove(listId);
}
},
I edited the working code with the help of #MasterAM It'w working now! No Console error anymore.

Related

Discord.js: Cannot Read Property "Name" of Null - How do I fix this?

I figured out how to make my Discord bot send an image to a certain channel whenever a specific user plays a specific game, but I have another problem.
When the application closes, I get this error saying, "Cannot read property 'name' of null." How do I fix this?
I haven't tried anything because I don't know anything about how I should use null.
// Game Detector \\
client.on("presenceUpdate", (oldMember, newMember) => {
if(newMember.id === '406742915352756235') {
if(newMember.presence.game.name === 'ROBLOX') { // New Example: ROBLOX
console.log('ROBLOX detected!');
client.channels.get('573671522116304901').send('**Joining Game:**', {
files: [
"https://cdn.discordapp.com/attachments/567519197052272692/579177282283896842/rblx1.png"
]
});
}
}
});
I expected the code to work, even when the application closes. Instead, it cannot read name of null. How can I fix this error?
This error is most likely thrown when the user stops playing a game, because newMember.presence.game will logically be null. Then, when you try to read name of newMember.presence.game, you receive your error.
Use this revised code:
client.on('presenceUpdate', (oldMember, newMember) => {
if (newMember.id !== '406742915352756235') return; // only check for this user
if (newMember.presence.game && newMember.presence.game.name === 'ROBLOX') {
console.log('ROBLOX detected.');
const channel = client.channels.get('573671522116304901');
if (!channel) return console.log('Unable to find channel.');
channel.send('**Joining Game:**', {
files: ['https://cdn.discordapp.com/attachments/567519197052272692/579177282283896842/rblx1.png']
}).catch(console.error);
}
});

Asteroid Oauth loginServiceConfiguration: 'google' of undefined

I've followed the 'naive' implementation in the project README: https://github.com/mondora/asteroid-oauth-mixin
The only difference in my code from the example is changing the arrow function to a traditional for the usage of this.
asteroid.ddp.on("added", ({collection, id, fields}: { collection: string; fields: {}, id: string }) => {
if (collection === "meteor_accounts_loginServiceConfiguration") {
asteroid.loginServiceConfiguration = {
...asteroid.loginServiceConfiguration,
[id]: {
_id: id,
...fields
}
};
}
});
});
asteroid.getServiceConfig = function(providerName: string) { // ts file
return this.loginServiceConfiguration[providerName];
}
When I do asteroid.loginWith('google')
index.ts:50 Uncaught TypeError: Cannot read property 'google' of undefined
On the meteor backend I also installed meteor add accounts-base accounts-google because I assume this is a dependency.
What am I missing? Thanks!
I've tried adding DDP.loginServiceConfiguration = {} before the snippet above which resolves the error but creates a new error.
asteroid-oauth-mixin.js:787 Uncaught TypeError: Cannot read property 'clientId' of undefined
at getOauthClientId (asteroid-oauth-mixin.js:787)
at Object.getOptions (asteroid-oauth-mixin.js:720)
at Asteroid.loginWith (asteroid-oauth-mixin.js:104)
at LoginForm../src/routes/accounts/auth/LoginForm.tsx.LoginForm.handleLoginWithGoogle (
Also when I run meteor mongo should db.meteor_accounts_loginServiceConfiguration.find().count() be 0 ?
I needed to meteor add service-configuration and setup my configure-accounts.js and create a google clientId for the application.
This gets me to the point where I have a popup and can choose which user to auth with. Then I receive a new error about target origin mismatch, but I'm going to close this question as resolved.

Issues retrieving fbsdk Access Token and User ID

I am trying to retrieve the Access Token and User ID of the logged in user in my React Native App. For some reason when I tried to update the fbsdkcore package, it did not exist anymore. So, I tried to resolve it within the general fbsdk package.
I am calling the js file (of which I think retrieves the accesstoken) in the package as:
const AccessToken = require('react-native-fbsdk/js/FBAccessToken');
And subsequently in my code I try to log it so that I can see if it works, simply by:
console.log(AccessToken.getCurrentAccessToken());
console.log(AccessToken.getUserId);
But the log only returns:
2016-05-05 10:22:28.276 [info][tid:com.facebook.React.JavaScript] { _45: 0, _81: 0, _65: null, _54: null }
2016-05-05 10:22:28.277 [info][tid:com.facebook.React.JavaScript] undefined
Which does not seem to be the droids that im looking for.
I inspected the code for the js file in the fbsdk package and the getCurrentAccessToken code looks like this:
/**
* Getter for the access token that is current for the application.
*/
static getCurrentAccessToken(): Promise<?FBAccessToken> {
return new Promise((resolve, reject) => {
AccessToken.getCurrentAccessToken((tokenMap) => {
if (tokenMap) {
resolve(new FBAccessToken(tokenMap));
} else {
resolve(null);
}
});
});
}
Which of course seems reasonable. But since I get this really weird result when I try to call it, I get worried over that I have done something wrong in the bigger picture. I even modified the resolve(null) part of the code so that I could make sure of what happend. But it still returned the same weird "token".
The log also returns this error when logging in:
2016-05-05 10:22:07.630 AppName[15097:415865] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
But I think that is only because I don't have the facebook app on my xcode simulator.
Can anybody throw me a good guess on what I have done wrong??
GetCurrentAccestoken returns a promise.
Maybe you can try:
AccessToken.getCurrentAccessToken().then(
(data) => {
console.log(data.accessToken.toString())
}
)
Try this. It worked for me
AccessToken.getCurrentAccessToken().then(
(data) => {
console.log(data.accessToken)
console.log(data.userID);
});
LoginManager.logInWithReadPermissions(['public_profile']).then(
function (result) {
if (result.isCancelled) {
alert('Login cancelled');
} else {
// alert('Login success with permissions: ' +
// result.grantedPermissions.toString());
AccessToken.getCurrentAccessToken().then(
(data) => {
doLoginViaFb(data.userID, data.accessToken);
}
);
alert(result);
console.log(result.toString());
console.log(JSON.stringify(result));
}
},
function (error) {
alert('Login fail with error: ' + error);
}
);

MeteorJS unexpected behaviour when calling server methods

Some how sequence or delay on server calls brings different behaviour. Code should explain this more clearly.
let editProfile = function (e) {
e.preventDefault();
let info = {};
info.username = $(".editProfile #usernameInput").val();
info.email = $(".editProfile #emailInput").val();
let picture = $(".editProfile #imageInput")[0].files[0];
if (picture) { <-|
Images.insert(picture); |Problem
} |
Meteor.call("editProfile", this, info); <-|
};
this works fine but when I try to change the sequence of these calls I get error in the console.
Meteor.call("editProfile", this, info); <-|
if (picture) { |Error is given
Images.insert(picture); |
} <-|
Error in browser:
Failed to load resource: the server responded with a status of 404 (Not Found)
Error: "Queue" failed [404] Not Found [404] [undefined], Error: failed [404] Not Found [404] [undefined]
at cfs_upload-http.js:351
at cfs_upload-http.js:77
at underscore.js:750
at XMLHttpRequest.xhr.onreadystatechange (cfs_upload-http.js:200)
If I try to do something like this: (no error is given)
Meteor.call("editProfile", this, info);
setTimeout(function () {
if (picture) {
Images.insert(picture);
}
},2000);
I would really like to know why this behaviour is affected by timeouts/sequence.

Template.meteorError.rendered doesn't work in errors meteor package

I am trying to use meteor-errors package in my meteor project.
It has two main files with javascript code:
errors_list.js:
Template.meteorErrors.helpers({
errors: function() {
return Errors.collection.find();
}
});
Template.meteorError.rendered = function() {
var error = this.data;
Meteor.defer(function() {
Errors.collection.update(error._id, {$set: {seen: true}});
});
};
errors.js:
Errors = {
// Local (client-only) collection
collection: new Meteor.Collection(null),
throw: function(message) {
Errors.collection.insert({message: message, seen: false})
},
clearSeen: function() {
Errors.collection.remove({seen: true});
}
};
But looks like Template.meteorError.rendered method doesn't work. And I can't set status of elements from my error's collection as seen: true.
When I call for example:
(server)
throw new Meteor.Error 401, "You need to login to add a new address"
(client)
Meteor.call "verify_address", address, name, (error, result) ->
if error
Errors.throw error.reason
I got this error message in my markup, but my browser console shows:
Errors.collection.find().fetch()
[Object]
_id: "MZ8TzpsKCXaeC33Jn"
message: "Address not the correct size"
seen: false
__proto__: Object
And message's seen attribute is still "false".
The initial problem was that an error has a 'X' icon that does not remove the error when clicked. How are we supposed to remove the errors?
The reason for the strange behavior is, you are manually throwing a Meteor.Error whereas your template is bound to a collection which is populated by calling Errors.throw(message)
Try this:
Errors.throw('You need to login to add a new address');

Categories

Resources