|
|
@@ -1,5 +1,3 @@
|
|
|
-import { useSession } from "vinxi/http"
|
|
|
-import { createClient } from "@openauthjs/openauth/client"
|
|
|
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"
|
|
|
@@ -8,18 +6,21 @@ import { query, redirect } from "@solidjs/router"
|
|
|
import { AccountTable } from "@opencode/cloud-core/schema/account.sql.js"
|
|
|
import { Actor } from "@opencode/cloud-core/actor.js"
|
|
|
|
|
|
-export async function withActor<T>(fn: () => T) {
|
|
|
- const actor = await getActor()
|
|
|
- return Actor.provide(actor.type, actor.properties, fn)
|
|
|
-}
|
|
|
+import { createClient } from "@openauthjs/openauth/client"
|
|
|
+import { useAuthSession } from "./auth.session"
|
|
|
+
|
|
|
+export const AuthClient = createClient({
|
|
|
+ clientID: "app",
|
|
|
+ issuer: import.meta.env.VITE_AUTH_URL,
|
|
|
+})
|
|
|
|
|
|
export const getActor = query(async (): Promise<Actor.Info> => {
|
|
|
"use server"
|
|
|
const evt = getRequestEvent()
|
|
|
const url = new URL(evt!.request.headers.get("referer") ?? evt!.request.url)
|
|
|
const auth = await useAuthSession()
|
|
|
- const [, workspaceHint] = url.pathname.split("/").filter((x) => x.length > 0)
|
|
|
- if (!workspaceHint) {
|
|
|
+ const splits = url.pathname.split("/").filter(Boolean)
|
|
|
+ if (splits[0] !== "workspace") {
|
|
|
if (auth.data.current) {
|
|
|
const current = auth.data.account[auth.data.current]
|
|
|
return {
|
|
|
@@ -49,6 +50,7 @@ export const getActor = query(async (): Promise<Actor.Info> => {
|
|
|
properties: {},
|
|
|
}
|
|
|
}
|
|
|
+ const workspaceHint = splits[1]
|
|
|
const accounts = Object.keys(auth.data.account)
|
|
|
const result = await Database.transaction(async (tx) => {
|
|
|
return await tx
|
|
|
@@ -74,32 +76,3 @@ export const getActor = query(async (): Promise<Actor.Info> => {
|
|
|
}
|
|
|
throw redirect("/auth/authorize")
|
|
|
}, "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() { }
|