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:Jump to 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),...2 Replies
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):
thank you so much!!