Get Stripe subscription by User Id

I'm getting successfully subscription on server side using auth.api.listActiveSubscriptions, but i'd like to get user subscription by userId. The documentation doesn't specifies how can i do it. Exists any form to do that using the plugin or i need to implement the full subscription retrival by userId from scratch?
Solution:
Hello João! You could query the DB directly, this is an example using Drizzle but it's mostly the same (the referenceId can be either the user ID or the org ID): ``` export const getSubscription = async (referenceId: string) => { return db.query.subscriptions.findFirst({ where: eq(subscriptionsTable.referenceId, referenceId),...
Jump to solution
2 Replies
Solution
Giordano Piazza
Giordano Piazza3mo ago
Hello João! You could query the DB directly, this is an example using Drizzle but it's mostly the same (the referenceId can be either the user ID or the org ID):
export const getSubscription = async (referenceId: string) => {
return db.query.subscriptions.findFirst({
where: eq(subscriptionsTable.referenceId, referenceId),
})
}
export const getSubscription = async (referenceId: string) => {
return db.query.subscriptions.findFirst({
where: eq(subscriptionsTable.referenceId, referenceId),
})
}
João Pedro
João PedroOP3mo ago
thank you so much!!

Did you find this page helpful?