1- import { useSession } from "vinxi/http"
2- import { createClient } from "@openauthjs/openauth/client"
31import { getRequestEvent } from "solid-js/web"
42import { and , Database , eq , inArray } from "@opencode/cloud-core/drizzle/index.js"
53import { WorkspaceTable } from "@opencode/cloud-core/schema/workspace.sql.js"
@@ -8,18 +6,21 @@ import { query, redirect } from "@solidjs/router"
86import { AccountTable } from "@opencode/cloud-core/schema/account.sql.js"
97import { Actor } from "@opencode/cloud-core/actor.js"
108
11- export async function withActor < T > ( fn : ( ) => T ) {
12- const actor = await getActor ( )
13- return Actor . provide ( actor . type , actor . properties , fn )
14- }
9+ import { createClient } from "@openauthjs/openauth/client"
10+ import { useAuthSession } from "./auth.session"
11+
12+ export const AuthClient = createClient ( {
13+ clientID : "app" ,
14+ issuer : import . meta. env . VITE_AUTH_URL ,
15+ } )
1516
1617export const getActor = query ( async ( ) : Promise < Actor . Info > => {
1718 "use server"
1819 const evt = getRequestEvent ( )
1920 const url = new URL ( evt ! . request . headers . get ( "referer" ) ?? evt ! . request . url )
2021 const auth = await useAuthSession ( )
21- const [ , workspaceHint ] = url . pathname . split ( "/" ) . filter ( ( x ) => x . length > 0 )
22- if ( ! workspaceHint ) {
22+ const splits = url . pathname . split ( "/" ) . filter ( Boolean )
23+ if ( splits [ 0 ] !== "workspace" ) {
2324 if ( auth . data . current ) {
2425 const current = auth . data . account [ auth . data . current ]
2526 return {
@@ -49,6 +50,7 @@ export const getActor = query(async (): Promise<Actor.Info> => {
4950 properties : { } ,
5051 }
5152 }
53+ const workspaceHint = splits [ 1 ]
5254 const accounts = Object . keys ( auth . data . account )
5355 const result = await Database . transaction ( async ( tx ) => {
5456 return await tx
@@ -74,32 +76,3 @@ export const getActor = query(async (): Promise<Actor.Info> => {
7476 }
7577 throw redirect ( "/auth/authorize" )
7678} , "actor" )
77-
78- export const AuthClient = createClient ( {
79- clientID : "app" ,
80- issuer : import . meta. env . VITE_AUTH_URL ,
81- } )
82-
83- export interface AuthSession {
84- account : Record <
85- string ,
86- {
87- id : string
88- email : string
89- }
90- >
91- current ?: string
92- }
93-
94- export function useAuthSession ( ) {
95- return useSession < AuthSession > ( {
96- password : "0" . repeat ( 32 ) ,
97- name : "auth" ,
98- cookie : {
99- secure : false ,
100- httpOnly : true ,
101- } ,
102- } )
103- }
104-
105- export function AuthProvider ( ) { }
0 commit comments