W
Wasp2mo ago
2euxs

How can I get user current plan in opensaas template

How can I get user current plan in opensaas template ?
3 Replies
kapa.ai
kapa.ai2mo ago
Hi @2euxs. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To get the user's current plan in the OpenSaaS template, you can access the user object which contains information about their subscription status. Here's how you can do it: 1. On the client-side: You can use the useAuth hook or the user prop (if authRequired is set to true for the page) to access the user object. The user object will contain fields related to the subscription status.
import { useAuth } from 'wasp/client/auth'

const MyComponent = () => {
const { data: user } = useAuth()

if (user) {
console.log(user.subscriptionStatus)
console.log(user.subscriptionTier)
}

// ... rest of your component
}

import { useAuth } from 'wasp/client/auth'

const MyComponent = () => {
const { data: user } = useAuth()

if (user) {
console.log(user.subscriptionStatus)
console.log(user.subscriptionTier)
}

// ... rest of your component
}

Wasp Docs - Accessing the logged-in user (https://wasp-lang.dev/docs/auth/overview#on-the-client) 2. On the server-side: In your actions or queries, you can access the user object through the context parameter. The user object will contain the same subscription-related fields.
import { HttpError } from 'wasp/server'

export const myServerAction = async (args, context) => {
if (!context.user) {
throw new HttpError(401)
}

const { subscriptionStatus, subscriptionTier } = context.user

// Use subscriptionStatus and subscriptionTier as needed
}

import { HttpError } from 'wasp/server'

export const myServerAction = async (args, context) => {
if (!context.user) {
throw new HttpError(401)
}

const { subscriptionStatus, subscriptionTier } = context.user

// Use subscriptionStatus and subscriptionTier as needed
}

The exact fields you'll use to determine the current plan may vary depending on how the OpenSaaS template is set up, but typically you'll want to look at subscriptionStatus and subscriptionTier (or similar fields) on the user object. Keep in mind that the specific implementation might differ slightly based on the version of the OpenSaaS template you're using. If you're having trouble finding these fields, you may need to check the User entity definition in your Wasp file to see exactly how the subscription information is stored. Discord - OpenSaaS subscription status discussion (https://discord.com/channels/686873244791210014/1214979650803998781) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @2euxs, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Vinny (@Wasp)
Vinny (@Wasp)2mo ago
Hey @2euxs did that answer your question?
2euxs
2euxsOP2mo ago
Yes thank you
Want results from more Discord servers?
Add your server