AfterSave on PFUser checking if on creation or update - javascript

I am having difficulty in distinguishing between if a PFUser is being updated or if it is being saved for the first time. I implemented the solution found on parse.com here. However, it is not working as explained in the answer found at the link. I always get a false regardless of if it is on the creation or an update. Here is the code that I have implemented.
Parse.Cloud.afterSave(Parse.User, function(request) {
Parse.Cloud.useMasterKey();
//this error log prints false regardless of if the user is signing up.
// or having a key updated.
console.error(request.object.existed());
if (!request.object.existed()) {
//This is on sign up, the user has not existed prior.
//This doesn't work. This block of code is always run.
}
else {
//This is supposedly when the user is having a key updated.
//Unfortunately, this code is never run regardless.
}
)}
This code does not behave as I expect it to because the request.object.existed() always returns false. I think this may have to do that this is saving a PFUser and not some generic PFObject. Is there something I am missing using request.object.existed() on a PFUser afterSave? Thanks.

This seems to be an unresolved Parse cloud bug
Possible workaround is to check the difference between create and update times to see if your object is being updated or is being created.

Related

Why am I getting this firebase/firestore error?

Here is my query
const query = messagesRef.where('members', 'in', [`${currentUserId}`]).orderBy('createdAt')
I have created an index as well.
This is the error I get
Error: {"code":"failed-precondition","name":"FirebaseError"}
Which I assume is usually an index thing
Yes, the failed-precondition can be due to a missing index. It can also be manually thrown by a user though with any user-defined description, typically from within a Firebase Function. The category is the only thing that must confine to the convention:
https://cloud.google.com/datastore/docs/concepts/errors
Here's one example of such error common in App-Checked Firebase Functions:
if (context.app == undefined) {
throw new functions.https.HttpsError(
'failed-precondition',
'The function must be called from an App Check verified app.')
}
You may want to check your Function Logs to get the actual error description. If the issue happens locally, then your firestore-debug.log file should contain some useful information. Just to be certain it's actually an index issue or not.
If the issue is happening only on production, you may want to verify the contents of your firestore.indexes.json and compare to what's inside the Firebase Console under https://console.firebase.google.com/u/0/project/<PROJECT-NAME>/firestore/indexes.
If it's actually an index issue, there will be a URL provided inside the logs that you can click which will generate the index for you inside Firestore:
https://firebase.google.com/docs/firestore/query-data/indexing?authuser=0&hl=en#create_a_missing_index_through_an_error_message
I hope this helps track down the issue! I used failed-precondition for several different error types, some unrelated to Firestore or indexes.

Expected null to deeply equal [Array (1)]

just a brief question. I've been struggling to figure out what this error in javascript actually means: "Timed out retrying: expected null to deeply equal [Array (1)]
I'm basically working on a LocalStorage Shopping Cart and my code is actually based on this video: https://www.youtube.com/watch?v=uR3r3GJvQDY&t=417s
It's pretty much very identical. The code perfectly works on my system without any errors but as soon as I upload it to my university's server on which the code undergoes certain tests I receive the above-named error. It also doesn't really indicate in which line of the code the error is happening. My instructor only told me this usually happens when the cart should exist in the localStorage, however, it doesn't which means the localStorage returns NULL to the system.
For reference to the code please check: https://gist.github.com/prof3ssorSt3v3/3e15d06a8128d6ca7deaa831a7a1e52b
So, we basically create a cart called contents and we never remove empty the LocalStorage at any point in the code. How can the LocalStorage return null at some point then and cause the error?
For the init function I have this:
init(){
//check localStorage and initialize the contents of CART.contents
let _contents = localStorage.getItem(cart.KEY);
if(_contents){
cart.contents = JSON.parse(_contents);
}
else{
cart.contents = [];
cart.sync();
}
},
Thank you for your help in advance!

Ethereumjs-vm, run-transaction-complete example not printing storage

Running the example mentioned in the title, there is no output after the "---Storage---" line. According to my understanding, there should be a null_radix stored at the created address. (running gives no exceptions) please correct me if I’m wrong!
[update]
At the following part of the example at the runTx function I've noticed that we refresh the createdAddress variable at every transaction even though it doesn't register a new contract. Therefore it leaves us with the loss of our contract's address and the readStorage function won't print any output.
I've fixed it by checking the createdAddress property for null before saving the value.
if (returns.createdAddress) {
createdAddress = results.createdAddress
console.log('address created: ' + createdAddress.toString('hex'))
}

Check localStorage is set to a specific value?

I'd really appreciate some help on this, I really can't see my issue here.
For some reason, sensing whether this data (loggedIn) is stored in localStorage with the value "yes" - I've tried the regular way of seeing if the localStorage is empty.
Here's my current code...
<script>
function checkLoggedIn()
{
if (localStorage.getItem("loggedIn") === null) {
alert("empty");
}else{
$(".topbar").html("<span>Saved Jobs(0)</span><span>Welcome, "+ storedUsername +"!</span>");
alert("working");
}
}
</script>
Then obviously I would call this with a body onload. For some reason, I can physically see the value of the localStorage when passing it as a variable, but checking it seems to not be working in the slightest.
I'm using this to simulate functionality of a user logging in, the rest of the functions to handle registration and logging in work fine to actually set the localStorage - so it's not a case of it not being stored.
Thanks for any help given people, it's really appreciated.

mongoose query / insert disorder bug?

I was writing a DB test (runned by Mocha), calling findOne after saving a document and found a weird behavior:
pseudocode here:
...
test1
A.save(check('A',done));
test2
B.save(check('B',done));
test3
C.save(check('C',done));
...
check = function(name, done) {
theModel.findOne({name:name}, function(err,result) {
assert.notEqual(result,null);
result.remove(done);
});
}
Then, the A test passes BUT the B test doesnt pass. I check the logs and I find a curious thing:
first its performed a insert, after a query, after a remove (for the first test, ok thats the expected behaviour).
After the first test, I got shocked when I saw the query was performed BEFORE the insert (and so the test failed and nothing got removed).
The third and so on behaves the same way! query is performed before insert :(
So the only test which passes is the first one (if I change A by B, then B is passed and A isnt). If I look at the mongodb collection I can see the other inserts which were performed after the query (and since assert failed, they werent removed)
I'm using mongoose 2.7.2, (but i was using a previous version, just updated to see if it was a solved bug). Help :(
I was wrong...
Didnt notice I was actually calling check before calling save (since I was calling the function inside the save method ... im so stupid and new to javascript).
Ok so I should perform the check in other way:
A.save(function(err, result) { check('A', done);})
my apologizes!

Categories