Dax Raad 5 months ago
parent
commit
042802848d

+ 25 - 23
cloud/app/src/context/auth.ts

@@ -2,7 +2,7 @@ import { getRequestEvent } from "solid-js/web"
 import { and, Database, eq, inArray } from "@opencode/cloud-core/drizzle/index.js"
 import { WorkspaceTable } from "@opencode/cloud-core/schema/workspace.sql.js"
 import { UserTable } from "@opencode/cloud-core/schema/user.sql.js"
-import { query, redirect } from "@solidjs/router"
+import { redirect } from "@solidjs/router"
 import { AccountTable } from "@opencode/cloud-core/schema/account.sql.js"
 import { Actor } from "@opencode/cloud-core/actor.js"
 
@@ -14,7 +14,7 @@ export const AuthClient = createClient({
   issuer: import.meta.env.VITE_AUTH_URL,
 })
 
-export const getActor = query(async (): Promise<Actor.Info> => {
+export const getActor = async (): Promise<Actor.Info> => {
   "use server"
   const evt = getRequestEvent()
   if (!evt) throw new Error("No request event")
@@ -53,27 +53,29 @@ export const getActor = query(async (): Promise<Actor.Info> => {
   }
   const workspaceHint = splits[1]
   const accounts = Object.keys(auth.data.account ?? {})
-  const result = await Database.transaction(async (tx) => {
-    return await tx
-      .select({
-        user: UserTable,
-      })
-      .from(AccountTable)
-      .innerJoin(UserTable, and(eq(UserTable.email, AccountTable.email)))
-      .innerJoin(WorkspaceTable, eq(WorkspaceTable.id, UserTable.workspaceID))
-      .where(and(inArray(AccountTable.id, accounts), eq(WorkspaceTable.id, workspaceHint)))
-      .limit(1)
-      .execute()
-      .then((x) => x[0])
-  })
-  if (result) {
-    return {
-      type: "user",
-      properties: {
-        userID: result.user.id,
-        workspaceID: result.user.workspaceID,
-      },
+  if (accounts.length) {
+    const result = await Database.transaction(async (tx) => {
+      return await tx
+        .select({
+          user: UserTable,
+        })
+        .from(AccountTable)
+        .innerJoin(UserTable, and(eq(UserTable.email, AccountTable.email)))
+        .innerJoin(WorkspaceTable, eq(WorkspaceTable.id, UserTable.workspaceID))
+        .where(and(inArray(AccountTable.id, accounts), eq(WorkspaceTable.id, workspaceHint)))
+        .limit(1)
+        .execute()
+        .then((x) => x[0])
+    })
+    if (result) {
+      return {
+        type: "user",
+        properties: {
+          userID: result.user.id,
+          workspaceID: result.user.workspaceID,
+        },
+      }
     }
   }
   throw redirect("/auth/authorize")
-}, "actor")
+}

+ 0 - 9
cloud/app/src/context/auth.withActor.ts

@@ -1,16 +1,7 @@
 import { Actor } from "@opencode/cloud-core/actor.js"
 import { getActor } from "./auth"
-import { query } from "@solidjs/router"
 
 export async function withActor<T>(fn: () => T) {
   const actor = await getActor()
   return Actor.provide(actor.type, actor.properties, fn)
 }
-
-export function actorQuery<T>(cb: () => T, name: string) {
-  "use server"
-  return query(async () => {
-    const actor = await getActor()
-    return withActor(cb)
-  }, name)
-}

+ 1 - 1
packages/sdk/js/src/server.ts

@@ -1,5 +1,5 @@
 import { spawn } from "node:child_process"
-import { Config } from "./gen/types.gen.js"
+import { type Config } from "./gen/types.gen.js"
 
 export type ServerOptions = {
   hostname?: string