summaryrefslogtreecommitdiffhomepage
path: root/packages/console/function
diff options
context:
space:
mode:
authorFrank <[email protected]>2025-10-06 16:15:10 -0400
committerFrank <[email protected]>2025-10-06 17:13:19 -0400
commit9e8fd16e6e4154ae0bccff8342e4b0c7780d8db8 (patch)
treec9f936bfcaf7cf7f275334e869738c87989a2362 /packages/console/function
parent1b17d8070bcddeddaea3dea403f031a161539901 (diff)
downloadopencode-9e8fd16e6e4154ae0bccff8342e4b0c7780d8db8.tar.gz
opencode-9e8fd16e6e4154ae0bccff8342e4b0c7780d8db8.zip
wip: zen
Diffstat (limited to 'packages/console/function')
-rw-r--r--packages/console/function/src/auth.ts22
1 files changed, 19 insertions, 3 deletions
diff --git a/packages/console/function/src/auth.ts b/packages/console/function/src/auth.ts
index 91f9b5045..e991e8c22 100644
--- a/packages/console/function/src/auth.ts
+++ b/packages/console/function/src/auth.ts
@@ -11,6 +11,9 @@ import { Workspace } from "@opencode-ai/console-core/workspace.js"
import { Actor } from "@opencode-ai/console-core/actor.js"
import { Resource } from "@opencode-ai/console-resource"
import { User } from "@opencode-ai/console-core/user.js"
+import { and, Database, eq, isNull } from "@opencode-ai/console-core/drizzle/index.js"
+import { WorkspaceTable } from "@opencode-ai/console-core/schema/workspace.sql.js"
+import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js"
type Env = {
AuthStorage: KVNamespace
@@ -123,9 +126,22 @@ export default {
})
}
await Actor.provide("account", { accountID, email }, async () => {
- const workspaceCount = await User.joinInvitedWorkspaces()
- if (workspaceCount === 0) {
- await Workspace.create()
+ await User.joinInvitedWorkspaces()
+ const workspaces = await Database.transaction(async (tx) =>
+ tx
+ .select({ id: WorkspaceTable.id })
+ .from(WorkspaceTable)
+ .innerJoin(UserTable, eq(UserTable.workspaceID, WorkspaceTable.id))
+ .where(
+ and(
+ eq(UserTable.accountID, accountID),
+ isNull(UserTable.timeDeleted),
+ isNull(WorkspaceTable.timeDeleted),
+ ),
+ ),
+ )
+ if (workspaces.length === 0) {
+ await Workspace.create({ name: "Default" })
}
})
return ctx.subject("account", accountID, { accountID, email })