From 9e8fd16e6e4154ae0bccff8342e4b0c7780d8db8 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 6 Oct 2025 16:15:10 -0400 Subject: wip: zen --- packages/console/function/src/auth.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'packages/console/function/src') 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 }) -- cgit v1.2.3