【发布时间】:2021-06-21 21:51:28
【问题描述】:
我正在处理条带扩展,但是当我传递 uid 时,它给了我错误“firebase__WEBPACK_IMPORTED_MODULE_3___default.a.auth.onAuthStateChanged 不是一个函数”......所以有什么建议我该如何解决这个错误??
这是我的代码:
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 });
}
});
}
}
)}
任何建议我该如何解决这个错误???
【问题讨论】:
标签: reactjs firebase stripe-payments firebase-extensions