I'm working on stripe extension but when i pass the uid it gives me error "firebase__WEBPACK_IMPORTED_MODULE_3___default.a.auth.onAuthStateChanged is not a function"...So any suggestion how can i fix this error??
Here is my code :
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 });
}
});
}
}
)}
Any suggestion How can i fix this error???