Skip to content

Commit 5f7bba1

Browse files
committed
wip: zen
1 parent 4663ea5 commit 5f7bba1

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

packages/console/app/src/context/auth.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getRequestEvent } from "solid-js/web"
2-
import { and, Database, eq, inArray, sql } from "@opencode-ai/console-core/drizzle/index.js"
2+
import { and, Database, eq, inArray, isNull, sql } from "@opencode-ai/console-core/drizzle/index.js"
33
import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js"
44
import { redirect } from "@solidjs/router"
55
import { Actor } from "@opencode-ai/console-core/actor.js"
@@ -56,7 +56,13 @@ export const getActor = async (workspace?: string): Promise<Actor.Info> => {
5656
tx
5757
.select()
5858
.from(UserTable)
59-
.where(and(eq(UserTable.workspaceID, workspace), inArray(UserTable.accountID, accounts)))
59+
.where(
60+
and(
61+
eq(UserTable.workspaceID, workspace),
62+
isNull(UserTable.timeDeleted),
63+
inArray(UserTable.accountID, accounts),
64+
),
65+
)
6066
.limit(1)
6167
.execute()
6268
.then((x) => x[0]),

packages/console/app/src/routes/auth/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Actor } from "@opencode-ai/console-core/actor.js"
2-
import { and, Database, eq, isNull } from "@opencode-ai/console-core/drizzle/index.js"
2+
import { and, Database, desc, eq, isNull } from "@opencode-ai/console-core/drizzle/index.js"
33
import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js"
44
import { WorkspaceTable } from "@opencode-ai/console-core/schema/workspace.sql.js"
55
import { redirect } from "@solidjs/router"
@@ -8,7 +8,7 @@ import { withActor } from "~/context/auth.withActor"
88

99
export async function GET(input: APIEvent) {
1010
try {
11-
const workspaces = await withActor(async () => {
11+
const workspaceID = await withActor(async () => {
1212
const actor = Actor.assert("account")
1313
return Database.transaction(async (tx) =>
1414
tx
@@ -21,10 +21,13 @@ export async function GET(input: APIEvent) {
2121
isNull(UserTable.timeDeleted),
2222
isNull(WorkspaceTable.timeDeleted),
2323
),
24-
),
24+
)
25+
.orderBy(desc(UserTable.timeSeen))
26+
.limit(1)
27+
.then((x) => x[0]?.id),
2528
)
2629
})
27-
return redirect(`/workspace/${workspaces[0].id}`)
30+
return redirect(`/workspace/${workspaceID}`)
2831
} catch {
2932
return redirect("/auth/authorize")
3033
}

packages/console/app/src/routes/workspace-picker.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ const getWorkspaces = query(async () => {
2323
})
2424
.from(UserTable)
2525
.innerJoin(WorkspaceTable, eq(UserTable.workspaceID, WorkspaceTable.id))
26-
.where(and(eq(UserTable.accountID, Actor.account()), isNull(WorkspaceTable.timeDeleted))),
26+
.where(
27+
and(
28+
eq(UserTable.accountID, Actor.account()),
29+
isNull(WorkspaceTable.timeDeleted),
30+
isNull(UserTable.timeDeleted),
31+
),
32+
),
2733
)
2834
})
2935
}, "workspaces")

0 commit comments

Comments
 (0)