解析错误:意外的令牌条带?斜线

问题描述

当我用 functions.auth.user().onCreate(async (user) => { 替换 functions.https.onRequest((req,res) => { 时,我最终收到以下错误

解析错误:意外的标记stripeslint

我收到 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
}

解决方法

您需要在代码中调整两件事:

  1. 在声明 HTTPS 云函数时使用 async 关键字。 functions.https.onRequest(async (req,res) => {...}
  2. 使用 create() 方法的 promise 版本正确终止您的云函数。有关此关键方面的更多详细信息,请参阅 https://firebase.google.com/docs/functions/terminate-functions