⚡ Make the default workspace plan configurable
Set it with a `DEFAULT_WORKSPACE_PLAN` env variable Closes #152
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
import prisma from '@/lib/prisma'
|
||||
import { authenticatedProcedure } from '@/utils/server/trpc'
|
||||
import { TRPCError } from '@trpc/server'
|
||||
import { Plan } from 'db'
|
||||
import { Workspace, workspaceSchema } from 'models'
|
||||
import { z } from 'zod'
|
||||
import { parseWorkspaceDefaultPlan } from '../../utils'
|
||||
|
||||
export const createWorkspaceProcedure = authenticatedProcedure
|
||||
.meta({
|
||||
@ -39,8 +39,7 @@ export const createWorkspaceProcedure = authenticatedProcedure
|
||||
message: 'Workspace with same name already exists',
|
||||
})
|
||||
|
||||
const plan =
|
||||
process.env.ADMIN_EMAIL === user.email ? Plan.LIFETIME : Plan.FREE
|
||||
const plan = parseWorkspaceDefaultPlan(user.email ?? '')
|
||||
|
||||
const newWorkspace = (await prisma.workspace.create({
|
||||
data: {
|
||||
|
@ -1,2 +1,3 @@
|
||||
export { WorkspaceProvider, useWorkspace } from './WorkspaceProvider'
|
||||
export * from './components'
|
||||
export { parseWorkspaceDefaultPlan } from './utils'
|
||||
|
@ -1,2 +1,3 @@
|
||||
export * from './parseNewName'
|
||||
export * from './parseWorkspaceDefaultPlan'
|
||||
export * from './setWorkspaceIdInLocalStorage'
|
||||
|
@ -0,0 +1,9 @@
|
||||
import { Plan } from 'db'
|
||||
|
||||
export const parseWorkspaceDefaultPlan = (userEmail: string) => {
|
||||
if (process.env.ADMIN_EMAIL === userEmail) return Plan.LIFETIME
|
||||
const defaultPlan = process.env.DEFAULT_WORKSPACE_PLAN as Plan | undefined
|
||||
if (defaultPlan && Object.values(Plan).includes(defaultPlan))
|
||||
return defaultPlan
|
||||
return Plan.FREE
|
||||
}
|
Reference in New Issue
Block a user