I am unable to fetch the current user in my cloud code:
Parse.Cloud.beforeSave('ChatConversation', async (request) => {
const Inbox = Parse.Object.extend("ChatInbox");
const query = new Parse.Query(Inbox);
const user = request.user;
await user.fetch({useMasterKey: true});
const userId = user.get('username');
const inboxId = request.object.get('inbox').id;
query.equalTo('objectId', inboxId );
return query.find().then(async function(res){
const result = res[0];
result.remove("whosTyping", userId);
await result.save();
});
});
And in my flutter debug this is the error output:
flutter: ╭-- Parse Response
Class: sendMessage
Function: ParseApiRQ.execute
Status Code: 141
Type: ScriptError
Error: Cannot read properties of undefined (reading 'fetch')
What am I doing wrong in here? Am I lacking? Please help me out! Thank you so much!
Related
My App ID is added to my react.js like that:
import * as Realm from "realm-web";
const REALM_APP_ID = "memeified_data-knivd";
const app = new Realm.App({ id: REALM_APP_ID });
My getAllData works well using the MongoDB App terminal:
But when I use the following code:
const [mainData, setData] = useState(null)
useEffect(() => {
const fetchData = async () => {
const data = await user.functions.getAllData()
setData(data);
}
fetchData()
.catch(console.error);;
}, [])
The code returns this console error:
TypeError: Cannot read properties of null (reading 'functions')
What could go wrong here?
I'm calling a firebase cloud function to create a stripe user, I'm getting this error in the logs "Detailed stack trace: Error: Cannot find module '#google-cloud/firestore'" but I'm puzzled because I have firestore in my dependencies.
does anybody know how to fix it?
cloud function
const functions = require("firebase-functions");
//const firestore = require("#google-cloud/firestore");
const { Configuration, PlaidApi, PlaidEnvironments } = require("plaid");
const stripe = require("stripe")(
"sk_stripe"
);
const admin = require("firebase-admin");
admin.initializeApp();
const db = admin.firestore();
const auth = admin.auth();
//create stripe customer
exports.createStripeUser = functions.https.onCall(async (data, context) => {
const phoneNum = data.phone;
const uid = context.auth.uid;
if (uid === null) {
console.log("Illegal access attempt due to unauthenticated attempt.");
throw new functions.https.HttpsError("internal", "Illegal access attempt");
}
return stripe.customers
.create({ phone: phoneNum })
.then((customer) => {
return customer["id"];
})
.then((customerId) => {
admin.firestore().collection("users").doc(uid).set({
stripeId: customerId,
phone: phoneNum,
id: uid,
});
})
.catch((err) => {
console.log(err);
throw new functions.https.HttpsError(
"internal",
" Unable to create Stripe user : " + err
);
});
});
dependencies
thanks
I have a hapijs project which is using the hapi-mongodb plugin.
In the handler I am using the hapi-mongodb plugin to make db calls. See below
internals.getById = async (request, h) => {
try {
const db = request.mongo.db;
const ObjectId = request.mongo.ObjectID;
const query = {
_id: ObjectId(request.params.id)
};
const record = await db.collection(internals.collectionName).findOne(query);
//etc.....
I want to be able to test this using server.inject(), but I am not sure how to stub the request.mongo.db and the request.mongo.ObjectID
it('should return a 200 HTTP status code', async () => {
const server = new Hapi.Server();
server.route(Routes); //This comes from a required file
const options = {
method: 'GET',
url: `/testData/1`
};
//stub request.mongo.db and request.mongo.ObjectID
const response = await server.inject(options);
expect(response.statusCode).to.equal(200);
});
Any ideas?
I worked this out and realised that the mongo plugin decorates the server object which can be stubbed.
This script is supposed to retrieve the innerText of a DOM element, the elements selector is
('div[class=QzVHcLdwl2CEuEMpTUFaj]') and I've hand-tested the selector and called the getSharePrice function in the REPL which also works.
const { chromium } = require('playwright');
const util = require('util');
const setTimeoutPromise = util.promisify(setTimeout);
(async () => {
const userDataDir = 'path'
const browser = await chromium.launchPersistentContext(userDataDir, {headless: false });
const page = await browser.newPage();
await page.goto('https://robinhood.com', {timeout: 60000, waitUntil: 'domcontentloaded'});
await getSharePrice(page)
await setTimeoutPromise(1000);
await browser.close();
})();
async function getSharePrice(page) {
const price = await page.evaluate(() => {
return {
price: document.querySelector('div[class=QzVHcLdwl2CEuEMpTUFaj]').innerText.replace(/\D/g,'')
}
});
console.log(price)
}
for some reason, I am getting a (node:59324) UnhandledPromiseRejectionWarning: Error: Evaluation failed: TypeError: Cannot read property 'innerText' of null error, not sure why.
The only thing that I could come up with is that the element hasn't been loaded yet, causing it to evaluate to null which is why innerText can't be called.
adding await page.waitForSelector('div[class=QzVHcLdwl2CEuEMpTUFaj]') before my evaluate block fixed this. Looks like the issue was caused by the element not being loaded yet
I saw some other answers and I tried some of those unsuccessfully.
In my case, I created an iOS app and integrated Stripe payment method, so it reaches my javascript function at cloud functions. I'm actually able to see the payments I realizes within my stripe account but I couldn't manage to save it into our firestore database.
this is my setup at Google side:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const express = require('express');
const cors = require('cors')({origin: true});
const app = express();
const stripe = require('stripe')(functions.config().stripe.token);
//I've preset this data to firebase functions middleware
function charge(req, res) {
const body = (req.body);
const userId = body.userId;
const token = body.token;
const amount = body.amount;
const currency = body.currency;
// Charge card
stripe.charges.create({
amount,
currency,
description: 'Firebase Example',
source: token,
}).then(charge => {
send(res, 200, {
// I WANNA RECORD DATA INTO MY DATABASE HERE!!
message: 'Success',
charge,
});
}).catch(err => {
console.log(err);
send(res, 500, {
error: err.message,
});
});
}
function send(res, code, body) {
res.send({
statusCode: code,
body: JSON.stringify(body),
});
}
app.use(cors);
app.post('/', (req, res) => {
// Catch any unexpected errors to prevent crashing
try {
charge(req, res);
} catch(e) {
console.log(e);
send(res, 500, {
error: `The server received an unexpected error. Please
try again and contact the site admin if the error persists.`,
});
}
});
exports.charge = functions.https.onRequest(app);
And this is our database setup where I want to save like this:
- into payments > userId... I'll save each transaction this userId does with the fields: "token", "currency" and "amount".
Note: I already have all this values in my function and also have userId.
enter image description here