mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-22 18:24:21 +01:00
ignore: cloud solid fixes
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
"@solidjs/meta": "^0.29.4",
|
"@solidjs/meta": "^0.29.4",
|
||||||
"@solidjs/router": "^0.15.0",
|
"@solidjs/router": "^0.15.0",
|
||||||
"@solidjs/start": "^1.1.0",
|
"@solidjs/start": "^1.1.0",
|
||||||
"solid-js": "^1.9.5",
|
"solid-js": "catalog:",
|
||||||
"vinxi": "^0.5.7",
|
"vinxi": "^0.5.7",
|
||||||
"@opencode/cloud-core": "workspace:*"
|
"@opencode/cloud-core": "workspace:*"
|
||||||
},
|
},
|
||||||
|
|||||||
23
cloud/app/src/context/auth.session.ts
Normal file
23
cloud/app/src/context/auth.session.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { useSession } from "vinxi/http"
|
||||||
|
|
||||||
|
export interface AuthSession {
|
||||||
|
account: Record<
|
||||||
|
string,
|
||||||
|
{
|
||||||
|
id: string
|
||||||
|
email: string
|
||||||
|
}
|
||||||
|
>
|
||||||
|
current?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useAuthSession() {
|
||||||
|
return useSession<AuthSession>({
|
||||||
|
password: "0".repeat(32),
|
||||||
|
name: "auth",
|
||||||
|
cookie: {
|
||||||
|
secure: false,
|
||||||
|
httpOnly: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
import { useSession } from "vinxi/http"
|
|
||||||
import { createClient } from "@openauthjs/openauth/client"
|
|
||||||
import { getRequestEvent } from "solid-js/web"
|
import { getRequestEvent } from "solid-js/web"
|
||||||
import { and, Database, eq, inArray } from "@opencode/cloud-core/drizzle/index.js"
|
import { and, Database, eq, inArray } from "@opencode/cloud-core/drizzle/index.js"
|
||||||
import { WorkspaceTable } from "@opencode/cloud-core/schema/workspace.sql.js"
|
import { WorkspaceTable } from "@opencode/cloud-core/schema/workspace.sql.js"
|
||||||
@@ -8,18 +6,21 @@ import { query, redirect } from "@solidjs/router"
|
|||||||
import { AccountTable } from "@opencode/cloud-core/schema/account.sql.js"
|
import { AccountTable } from "@opencode/cloud-core/schema/account.sql.js"
|
||||||
import { Actor } from "@opencode/cloud-core/actor.js"
|
import { Actor } from "@opencode/cloud-core/actor.js"
|
||||||
|
|
||||||
export async function withActor<T>(fn: () => T) {
|
import { createClient } from "@openauthjs/openauth/client"
|
||||||
const actor = await getActor()
|
import { useAuthSession } from "./auth.session"
|
||||||
return Actor.provide(actor.type, actor.properties, fn)
|
|
||||||
}
|
export const AuthClient = createClient({
|
||||||
|
clientID: "app",
|
||||||
|
issuer: import.meta.env.VITE_AUTH_URL,
|
||||||
|
})
|
||||||
|
|
||||||
export const getActor = query(async (): Promise<Actor.Info> => {
|
export const getActor = query(async (): Promise<Actor.Info> => {
|
||||||
"use server"
|
"use server"
|
||||||
const evt = getRequestEvent()
|
const evt = getRequestEvent()
|
||||||
const url = new URL(evt!.request.headers.get("referer") ?? evt!.request.url)
|
const url = new URL(evt!.request.headers.get("referer") ?? evt!.request.url)
|
||||||
const auth = await useAuthSession()
|
const auth = await useAuthSession()
|
||||||
const [, workspaceHint] = url.pathname.split("/").filter((x) => x.length > 0)
|
const splits = url.pathname.split("/").filter(Boolean)
|
||||||
if (!workspaceHint) {
|
if (splits[0] !== "workspace") {
|
||||||
if (auth.data.current) {
|
if (auth.data.current) {
|
||||||
const current = auth.data.account[auth.data.current]
|
const current = auth.data.account[auth.data.current]
|
||||||
return {
|
return {
|
||||||
@@ -49,6 +50,7 @@ export const getActor = query(async (): Promise<Actor.Info> => {
|
|||||||
properties: {},
|
properties: {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const workspaceHint = splits[1]
|
||||||
const accounts = Object.keys(auth.data.account)
|
const accounts = Object.keys(auth.data.account)
|
||||||
const result = await Database.transaction(async (tx) => {
|
const result = await Database.transaction(async (tx) => {
|
||||||
return await tx
|
return await tx
|
||||||
@@ -74,32 +76,3 @@ export const getActor = query(async (): Promise<Actor.Info> => {
|
|||||||
}
|
}
|
||||||
throw redirect("/auth/authorize")
|
throw redirect("/auth/authorize")
|
||||||
}, "actor")
|
}, "actor")
|
||||||
|
|
||||||
export const AuthClient = createClient({
|
|
||||||
clientID: "app",
|
|
||||||
issuer: import.meta.env.VITE_AUTH_URL,
|
|
||||||
})
|
|
||||||
|
|
||||||
export interface AuthSession {
|
|
||||||
account: Record<
|
|
||||||
string,
|
|
||||||
{
|
|
||||||
id: string
|
|
||||||
email: string
|
|
||||||
}
|
|
||||||
>
|
|
||||||
current?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useAuthSession() {
|
|
||||||
return useSession<AuthSession>({
|
|
||||||
password: "0".repeat(32),
|
|
||||||
name: "auth",
|
|
||||||
cookie: {
|
|
||||||
secure: false,
|
|
||||||
httpOnly: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function AuthProvider() { }
|
|
||||||
7
cloud/app/src/context/auth.withActor.ts
Normal file
7
cloud/app/src/context/auth.withActor.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { Actor } from "@opencode/cloud-core/actor.js"
|
||||||
|
import { getActor } from "./auth"
|
||||||
|
|
||||||
|
export async function withActor<T>(fn: () => T) {
|
||||||
|
const actor = await getActor()
|
||||||
|
return Actor.provide(actor.type, actor.properties, fn)
|
||||||
|
}
|
||||||
@@ -2,7 +2,8 @@ import { Billing } from "@opencode/cloud-core/billing.js"
|
|||||||
import { Key } from "@opencode/cloud-core/key.js"
|
import { Key } from "@opencode/cloud-core/key.js"
|
||||||
import { action, createAsync, revalidate, query, useAction, useSubmission } from "@solidjs/router"
|
import { action, createAsync, revalidate, query, useAction, useSubmission } from "@solidjs/router"
|
||||||
import { createEffect, createSignal, For, onMount, Show } from "solid-js"
|
import { createEffect, createSignal, For, onMount, Show } from "solid-js"
|
||||||
import { getActor, withActor } from "~/context/auth"
|
import { getActor } from "~/context/auth"
|
||||||
|
import { withActor } from "~/context/auth.withActor"
|
||||||
|
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
// Keys related queries and actions
|
// Keys related queries and actions
|
||||||
@@ -47,8 +48,11 @@ const createPortalUrl = action(async (returnUrl: string) => {
|
|||||||
return withActor(() => Billing.generatePortalUrl({ returnUrl }))
|
return withActor(() => Billing.generatePortalUrl({ returnUrl }))
|
||||||
}, "portalUrl")
|
}, "portalUrl")
|
||||||
|
|
||||||
export default function() {
|
export default function () {
|
||||||
const actor = createAsync(() => getActor())
|
const actor = createAsync(() => getActor())
|
||||||
|
onMount(() => {
|
||||||
|
console.log("MOUNTED", actor())
|
||||||
|
})
|
||||||
|
|
||||||
/////////////////
|
/////////////////
|
||||||
// Keys section
|
// Keys section
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
"@solid-primitives/storage": "4.3.1",
|
"@solid-primitives/storage": "4.3.1",
|
||||||
"@solidjs/meta": "0.29.4",
|
"@solidjs/meta": "0.29.4",
|
||||||
"@solidjs/router": "0.15.3",
|
"@solidjs/router": "0.15.3",
|
||||||
"solid-js": "1.9.5",
|
"solid-js": "catalog:",
|
||||||
"solid-list": "0.3.0"
|
"solid-list": "0.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,8 @@
|
|||||||
"hono": "4.7.10",
|
"hono": "4.7.10",
|
||||||
"typescript": "5.8.2",
|
"typescript": "5.8.2",
|
||||||
"zod": "3.25.76",
|
"zod": "3.25.76",
|
||||||
"remeda": "2.26.0"
|
"remeda": "2.26.0",
|
||||||
|
"solid-js": "1.9.9"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
"remeda": "2.26.0",
|
"remeda": "2.26.0",
|
||||||
"sharp": "0.32.5",
|
"sharp": "0.32.5",
|
||||||
"shiki": "3.4.2",
|
"shiki": "3.4.2",
|
||||||
"solid-js": "1.9.7",
|
"solid-js": "catalog:",
|
||||||
"toolbeam-docs-theme": "0.4.6"
|
"toolbeam-docs-theme": "0.4.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
Reference in New Issue
Block a user