【发布时间】:2021-04-22 19:45:27
【问题描述】:
我对 firebase / firestore 有点陌生。我正在使用条纹 api。
一旦用户在预建的条带结帐页面上点击start trial,那么它应该转到firestore并创建一个名为subscriptions的新集合,其中包含所有用户信息。它似乎正在这样做,但是,我创建了一个名为 successPage 的页面,它基本上会检查以确保它创建了它。
请在下面找到代码:
const successPage = props => {
firebase.auth().onAuthStateChanged((user) => {
if(user) {
console.log("calling success page : " + user.uid)
//checking if user is paying for subscription
firestore.collection('customers').doc(user.uid).collection('subscriptions')
.where('status', 'in', ['trialing', 'active']).get()
.then(activeSubscriptions => {
// if this is true, the user has no active subscription.
if (activeSubscriptions.empty === true) {
console.log(user.uid)
firestore.collection('customers').doc(user.uid)
.get().then(
doc => {
if (doc.exists) {
firestore.collection('customers').doc(user.uid).collection('subscriptions').get().
then(sub => {
if (sub.docs.length > 0) {
var activityStatus = "canceled"
createCheckoutSession(activityStatus)
console.log('subcollection exists');
} else {
alert("Your account has been created, but your payment details we're not successfully created. You will now be redirected to the checkout page")
createCheckoutSession()
console.log(user.uid)
console.log("does not exist!")
}
});
}
});
} else if (activeSubscriptions.size > 1){
alert("you have more then one active subscription. please manage your subscriptions and cancel one of your subscriptions to access the application")
} else {
firestore.collection("profiledata").doc(user.uid).update({
accountStatus: "active"
}).then (() => {
firestore
.collection("roger@x.ca")
.add({
to: user.email,
message: {
},
})
.then(() => console.log("email out for delivery!"));
props.history.push('/clients')
})
}
});
}
})
return (
<input type="hidden"></input>
)
}
它检查订阅集合,其中 status = 为试用或活动,然后检查订阅内的所有内容以查看发生了什么,但由于某种原因,它一直重定向到条带页面 (createCheckoutSession),即使订阅集合已创建。这是时间问题吗?
【问题讨论】:
标签: javascript node.js reactjs firebase google-cloud-firestore