【问题标题】:firebase__WEBPACK_IMPORTED_MODULE_3___default.a.auth.onAuthStateChanged is not a function Firebase reactfirebase__WEBPACK_IMPORTED_MODULE_3___default.a.auth.onAuthStateChanged 不是 Firebase 反应的函数
【发布时间】:2021-06-22 04:57:45
【问题描述】:

我正在使用这个条带扩展名,我正在尝试传递它给我的 uid 错误firebase__WEBPACK_IMPORTED_MODULE_3___default.a.auth.onAuthStateChanged is not a function 但我以前从未见过这个错误。请看下面的代码

import {loadStripe} from '@stripe/stripe-js';
import firebase from 'firebase';


const firestore = firebase.firestore();

firebase.auth().onAuthStateChanged((user) => {
  if(user) {
console.log(user.uid) ;
}
});

export async function createCheckoutSession(uid){
  firebase.auth.onAuthStateChanged((user) => {
    if (user){
      const checkoutSessionRef =  firestore
        .collection('customers')
        .doc(user.uid)
        .collection('checkout_sessions')
        .add({
          price: 'price id',
          success_url: window.location.origin,
          cancel_url: window.location.origin,
      });
// Wait for the CheckoutSession to get attached by the extension
    checkoutSessionRef.onSnapshot((snap) => {
      const { error, sessionId } = snap.data();
      if (error) {
    // Show an error to your customer and 
    // inspect your Cloud Function logs in the Firebase console.
      alert(`An error occured: ${error.message}`);
    }
    if (sessionId) {
    // We have a session, let's redirect to Checkout
    // Init Stripe
    const stripe =   loadStripe('pk_test_1234');
    stripe.redirectToCheckout({ sessionId });
    }
  });
  }
}
  )} 

有人有什么建议吗?

【问题讨论】:

  • createCheckoutSession 内你有firebase.auth.onAuthStateChanged。那应该是firebase.auth().onAuthStateChanged
  • @FrankvanPuffelen 当我这样做时它给出了同样的错误......你还有其他建议吗?
  • 这似乎不太可能。您可以编辑您的问题以显示更新后的代码吗?

标签: reactjs firebase firebase-authentication stripe-payments


【解决方案1】:

试试这个:

(async () =>{
    await firebase.auth().onAuthStateChanged((user) => {
    if(user) {
        console.log(user.uid) ;
    }
});
} )();

【讨论】:

  • 你有没有 firebase 配置对象,你是否在 firebase 控制台中激活了身份验证
  • 是的,我们都做了。我们在 firebase config 文件夹中设置了所有配置,并在 firebase 控制台端激活...代码设置为具有所有必要的字段,如 apiKey、authdomain、projectID、appID 等
  • 你在使用 react.js 以便我可以轻松地帮助你
  • 当我尝试此解决方案时,它给出了与以前相同的错误...您还有其他建议吗?
猜你喜欢
  • 2021-06-21
  • 2020-10-02
  • 1970-01-01
  • 1970-01-01
  • 2021-01-04
  • 2017-01-28
  • 2019-08-03
  • 2022-01-25
  • 1970-01-01
相关资源
最近更新 更多