首页 > 解决方案 > Firebase Stripe Extension - adding custom claims to user

问题描述

I'm integrating Stripe with firebase and firestore using the Run Subscription Payments with Stripe extension. When a user subscribes to the service I need to be able to decode the JWT and see if they are subscribed or not through a custom claim.

enter image description here

enter image description here

The logs on the function show that it is invalidating the custom claim. I'm unsure why this is happening.

标签: firebasegoogle-cloud-firestorefirebase-authenticationjwtstripe-payments

解决方案


从您提供的日志来看,您似乎有多个订阅(sub_KBpVfFzNclrhaG 和 sub_KBpV10rxE6jkkH),它们都绑定到同一个用户/客户。订阅 sub_KBpVfFzNclrhaG 的状态为活动或试用,因此自定义声明已正确添加。但是,订阅 sub_KBpV10rxE6jkkH 是在不久之后创建的(我假设状态为非活动或试用),它再次将用户的自定义声明更新为 null。您可以通过检查仪表板中两个订阅的状态来确认这是否正在发生。

您需要确保每个客户只有一个活动/试用订阅,这将是您在应用程序逻辑中检查的内容。这里有一个如何检查客户的活动/试用订阅的示例(https://github.com/stripe-samples/firebase-subscription-payments/blob/4cf116c163ba69f0f46bcc782e4162e0edf452a4/public/javascript/app.js#L121


推荐阅读