summaryrefslogtreecommitdiffhomepage
path: root/cloud
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-09-03 12:31:09 -0400
committerDax Raad <[email protected]>2025-09-03 12:32:03 -0400
commit59e550271d3c9bc50ebb8b7ba0d04eacd1e49e1a (patch)
tree01c62ec789806c12915f46d3714b8dc08cdae630 /cloud
parentafebe920b267431272bd4cc81111848ab5eb21a3 (diff)
downloadopencode-59e550271d3c9bc50ebb8b7ba0d04eacd1e49e1a.tar.gz
opencode-59e550271d3c9bc50ebb8b7ba0d04eacd1e49e1a.zip
wip: cloud
Diffstat (limited to 'cloud')
-rw-r--r--cloud/app/src/context/auth.ts115
-rw-r--r--cloud/app/src/context/auth.withActor.ts1
-rw-r--r--cloud/app/src/routes/workspace/[id].tsx6
3 files changed, 64 insertions, 58 deletions
diff --git a/cloud/app/src/context/auth.ts b/cloud/app/src/context/auth.ts
index ef81cccf1..e80604f8b 100644
--- a/cloud/app/src/context/auth.ts
+++ b/cloud/app/src/context/auth.ts
@@ -18,65 +18,70 @@ export const getActor = async (): Promise<Actor.Info> => {
"use server"
const evt = getRequestEvent()
if (!evt) throw new Error("No request event")
- const url = new URL(evt.request.headers.has("x-server-id") ? evt.request.headers.get("referer")! : evt.request.url)
- const auth = await useAuthSession()
- auth.data.account = auth.data.account ?? {}
- const splits = url.pathname.split("/").filter(Boolean)
- if (splits[0] !== "workspace") {
- const current = auth.data.account[auth.data.current ?? ""]
- if (current) {
- return {
- type: "account",
- properties: {
- email: current.email,
- accountID: current.id,
- },
+ if (evt.locals.actor) return evt.locals.actor
+ evt.locals.actor = (async () => {
+ console.log("getActor")
+ const url = new URL(evt.request.headers.has("x-server-id") ? evt.request.headers.get("referer")! : evt.request.url)
+ const auth = await useAuthSession()
+ const splits = url.pathname.split("/").filter(Boolean)
+ if (splits[0] !== "workspace") {
+ const account = auth.data.account ?? {}
+ const current = account[auth.data.current ?? ""]
+ if (current) {
+ return {
+ type: "account",
+ properties: {
+ email: current.email,
+ accountID: current.id,
+ },
+ }
+ }
+ if (Object.keys(account).length > 0) {
+ const current = Object.values(account)[0]
+ await auth.update((val) => ({
+ ...val,
+ current: current.id,
+ }))
+ return {
+ type: "account",
+ properties: {
+ email: current.email,
+ accountID: current.id,
+ },
+ }
}
- }
- if (Object.keys(auth.data.account ?? {}).length > 0) {
- const current = Object.values(auth.data.account)[0]
- await auth.update((val) => ({
- ...val,
- current: current.id,
- }))
return {
- type: "account",
- properties: {
- email: current.email,
- accountID: current.id,
- },
+ type: "public",
+ properties: {},
}
}
- return {
- type: "public",
- properties: {},
- }
- }
- const workspaceHint = splits[1]
- const accounts = Object.keys(auth.data.account ?? {})
- 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,
- },
+ const workspaceHint = splits[1]
+ const accounts = Object.keys(auth.data.account ?? {})
+ 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")
+ throw redirect("/auth/authorize")
+ })()
+ return evt.locals.actor
}
diff --git a/cloud/app/src/context/auth.withActor.ts b/cloud/app/src/context/auth.withActor.ts
index a61b728ef..5c87f1338 100644
--- a/cloud/app/src/context/auth.withActor.ts
+++ b/cloud/app/src/context/auth.withActor.ts
@@ -1,5 +1,6 @@
import { Actor } from "@opencode/cloud-core/actor.js"
import { getActor } from "./auth"
+import { getRequestEvent } from "solid-js/web"
export async function withActor<T>(fn: () => T) {
const actor = await getActor()
diff --git a/cloud/app/src/routes/workspace/[id].tsx b/cloud/app/src/routes/workspace/[id].tsx
index 17f4f85d2..84d2c10b3 100644
--- a/cloud/app/src/routes/workspace/[id].tsx
+++ b/cloud/app/src/routes/workspace/[id].tsx
@@ -42,12 +42,14 @@ const getBillingInfo = query(async () => {
"use server"
return withActor(async () => {
const actor = Actor.assert("user")
+ const now = Date.now()
const [user, billing, payments, usage] = await Promise.all([
User.fromID(actor.properties.userID),
Billing.get(),
Billing.payments(),
Billing.usages(),
])
+ console.log("duration", Date.now() - now)
return { user, billing, payments, usage }
})
}, "billingInfo")
@@ -67,9 +69,7 @@ export default function () {
/////////////////
// Keys section
/////////////////
- const keys = createAsync(() => listKeys(), {
- deferStream: true,
- })
+ const keys = createAsync(() => listKeys())
const createKeyAction = useAction(createKey)
const removeKeyAction = useAction(removeKey)
const createKeySubmission = useSubmission(createKey)