When I replace functions.auth.user().onCreate(async (user) => {
with functions.https.onRequest((req, res) => {
I end up getting the following error:
Parsing error: Unexpected token stripeslint
I get this error for strip.
const strip = require('stripe')('KeyString'); exports.createConnectAccount = functions.auth.user().onCreate(async (user) => {// functions.https.onRequest((req, res) => { // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/account/apikeys const account = await strip.accounts.create({ //get error here: strip type: 'express', }); let refURL = account.refresh_url let retURL = account.return_url console.log("mi caca la caca 00>", account, retURL, refURL, account.uid, account.userId, account.userRef, account.user, account.id, account.ref, account.pushId, account.customer_id) });
Packedge.json
{ "name": "functions", "description": "Cloud Functions for Firebase", "scripts": { "lint": "eslint .", "serve": "firebase emulators:start --only functions", "shell": "firebase functions:shell", "start": "npm run shell", "deploy": "firebase deploy --only functions", "logs": "firebase functions:log" }, "engines": { "node": "12" }, "main": "index.js", "dependencies": { "@google-cloud/logging": "^9.1.0", "firebase-admin": "^9.2.0", "firebase-functions": "^3.11.0", "stripe": "^8.56.0" }, "devDependencies": { "eslint": "^6.8.0", "eslint-plugin-promise": "^4.0.1", "firebase-functions-test": "^0.2.0" }, "private": true }
Answer
There are two things you need to adapt in your code:
- Use the
async
keyword when declaring the HTTPS Cloud Function.functions.https.onRequest(async (req, res) => {...}
. - Correctly terminate your cloud function by using the promise version of the
create()
method. See https://firebase.google.com/docs/functions/terminate-functions for more details on this key aspect.