feat(dashboard): 🛂 Limit create folder to Pro user
This commit is contained in:
18
apps/builder/services/stripe.ts
Normal file
18
apps/builder/services/stripe.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { User } from 'db'
|
||||
import { loadStripe } from '@stripe/stripe-js'
|
||||
import { sendRequest } from 'utils'
|
||||
|
||||
export const pay = async (user: User) => {
|
||||
if (!process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY)
|
||||
throw new Error('NEXT_PUBLIC_STRIPE_PUBLIC_KEY is missing in env')
|
||||
const stripe = await loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY)
|
||||
const { data, error } = await sendRequest<{ sessionId: string }>({
|
||||
method: 'POST',
|
||||
url: '/api/stripe/checkout',
|
||||
body: { email: user.email },
|
||||
})
|
||||
if (error || !data) return
|
||||
return stripe?.redirectToCheckout({
|
||||
sessionId: data?.sessionId,
|
||||
})
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import { User } from 'db'
|
||||
import { sendRequest } from 'utils'
|
||||
import { Plan, User } from 'db'
|
||||
import { isNotDefined, sendRequest } from 'utils'
|
||||
|
||||
export const updateUser = async (id: string, user: User) =>
|
||||
sendRequest({
|
||||
@ -7,3 +7,6 @@ export const updateUser = async (id: string, user: User) =>
|
||||
method: 'PUT',
|
||||
body: user,
|
||||
})
|
||||
|
||||
export const isFreePlan = (user?: User) =>
|
||||
isNotDefined(user) || user?.plan === Plan.FREE
|
||||
|
Reference in New Issue
Block a user