Skip to content

Commit

Permalink
fix: server side protection to prevent users to create more than two …
Browse files Browse the repository at this point in the history
…orgs on the free plan
  • Loading branch information
hughcrt committed Feb 17, 2024
1 parent 317beb3 commit 48d66a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Expand Up @@ -11,4 +11,5 @@ docker-compose*
.vscode
*.next
*.swp
/scripts
/scripts
.env
15 changes: 9 additions & 6 deletions packages/backend/src/api/v1/projects/index.ts
Expand Up @@ -36,6 +36,12 @@ projects.post("/", async (ctx: Context) => {
})
const { name } = bodySchema.parse(ctx.request.body)

const [org] = await sql`select * from org where id = ${orgId}`

if (org.plan === "free") {
ctx.throw(403, "You can't create more than two project under the free plan")
}

const newProject = {
name,
orgId,
Expand All @@ -49,18 +55,15 @@ projects.post("/", async (ctx: Context) => {
projectId: project.id,
apiKey: project.id,
}
sql`
insert into api_key ${sql(publicKey)}
`
sql`insert into api_key ${sql(publicKey)}`

const privateKey = [
{
type: "private",
projectId: project.id,
},
]
await sql`
insert into api_key ${sql(privateKey)}
`
await sql`insert into api_key ${sql(privateKey)}`
ctx.body = project
})

Expand Down

0 comments on commit 48d66a3

Please sign in to comment.