firebase error Uncaught (in promise) FirebaseError: 权限缺失或不足

时间:2021-03-13 16:02:47

标签: javascript reactjs firebase

我正在尝试使用我的 react 应用程序实现条带支付系统,我在其中使用 firebase 来存储用户数据。我从另一位开发人员那里接手了项目,但在尝试获取用户的 uid 以将信息连接在一起时遇到了问题。

我在运行 checkout.js 页面时收到错误 Uncaught (in promise) FirebaseError: Missing or insufficient permissions....这是我所拥有的:

user.js

    class UserStripe {
    constructor({ db, auth, firestoreEnvironment }) {
      this.db = db
      this.auth = auth
      this.collections = new StripeCollectionUtil({ db, firestoreEnvironment, auth })
      this.env = firestoreEnvironment
    }
  
    doCreateUser(uid, email, name, companyName) {
      if (!companyName) companyName = null
      return this.collections.getCollectionFor('users').doc(uid).set({
        email,
        name,
        companyName,
        areasAndTasks: JSON.stringify(defaultAreasAndTasks),
        environment: this.env
      })
    }
  
    getUserProfile() {
      let uid = this.auth.currentUser.uid
      return this.collections.getCollectionFor('users').doc(uid).get().then(doc => doc.data())
    }
  
    getAreasAndTasks() {
      return this.getUserProfile().then((userProfile) => JSON.parse(userProfile.areasAndTasks))
    }
  }
  
  module.exports = UserStripe

这是我的 checkout.js

    import firebase from 'firebase';
import getStripe from './stripe';

const firestore = firebase.firestore();

export async function createCheckoutSession(){

    // without uid
    
    // return firestore.collection()
    const checkoutSessionRef =  await firestore.collection('customers').doc().collection('checkout_sessions').add(
        
        {price : 'price_1IGEdTKDPaWWeL1ymwWH5Ubb',
         success_url : window.location.origin,
         cancel_url: window.location.origin,
    }
    );

    checkoutSessionRef.onSnapshot(async (snap) => {
        const {sessionid} = snap.data();
        if (sessionid) {
             const stripe = await getStripe()
             stripe.redirectToCheckout({sessionid})
        }
    });
}

如何将 uid 导入结帐页面,以免出现此错误?

0 个答案:

没有答案