【发布时间】: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