⚡ 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
|
||||
}
|
@ -3,7 +3,6 @@ import {
|
||||
PrismaClient,
|
||||
Prisma,
|
||||
Invitation,
|
||||
Plan,
|
||||
WorkspaceRole,
|
||||
WorkspaceInvitation,
|
||||
Session,
|
||||
@ -12,6 +11,7 @@ import type { Adapter, AdapterUser } from 'next-auth/adapters'
|
||||
import cuid from 'cuid'
|
||||
import { got } from 'got'
|
||||
import { generateId } from 'utils'
|
||||
import { parseWorkspaceDefaultPlan } from '@/features/workspace'
|
||||
|
||||
type InvitationWithWorkspaceId = Invitation & {
|
||||
typebot: {
|
||||
@ -53,11 +53,7 @@ export function CustomAdapter(p: PrismaClient): Adapter {
|
||||
name: data.name
|
||||
? `${data.name}'s workspace`
|
||||
: `My workspace`,
|
||||
...(process.env.ADMIN_EMAIL === data.email
|
||||
? { plan: Plan.LIFETIME }
|
||||
: {
|
||||
plan: Plan.FREE,
|
||||
}),
|
||||
plan: parseWorkspaceDefaultPlan(data.email),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Reference in New Issue
Block a user