MCPcopy Index your code
hub / github.com/anomalyco/opencode / getActor

Function getActor

packages/console/app/src/context/auth.ts:40–116  ·  view source on GitHub ↗
(workspace?: string)

Source from the content-addressed store, hash-verified

38}
39
40export const getActor = async (workspace?: string): Promise<Actor.Info> => {
41 "use server"
42 const evt = getRequestEvent()
43 if (!evt) throw new Error("No request event")
44 if (evt.locals.actor) return evt.locals.actor
45 evt.locals.actor = (async () => {
46 const auth = await useAuthSession()
47 if (!workspace) {
48 const account = auth.data.account ?? {}
49 const current = account[auth.data.current ?? ""]
50 if (current) {
51 return {
52 type: "account",
53 properties: {
54 email: current.email,
55 accountID: current.id,
56 },
57 }
58 }
59 if (Object.keys(account).length > 0) {
60 const current = Object.values(account)[0]
61 await auth.update((val) => ({
62 ...val,
63 current: current.id,
64 }))
65 return {
66 type: "account",
67 properties: {
68 email: current.email,
69 accountID: current.id,
70 },
71 }
72 }
73 return {
74 type: "public",
75 properties: {},
76 }
77 }
78 const accounts = Object.keys(auth.data.account ?? {})
79 if (accounts.length) {
80 const user = await Database.use((tx) =>
81 tx
82 .select()
83 .from(UserTable)
84 .where(
85 and(
86 eq(UserTable.workspaceID, workspace),
87 isNull(UserTable.timeDeleted),
88 inArray(UserTable.accountID, accounts),
89 ),
90 )
91 .limit(1)
92 .execute()
93 .then((x) => x[0]),
94 )
95 if (user) {
96 await Database.use((tx) =>
97 tx

Callers 2

[plan].tsxFile · 0.90
withActorFunction · 0.90

Calls 12

useAuthSessionFunction · 0.85
eqFunction · 0.85
redirectFunction · 0.85
updateMethod · 0.65
executeMethod · 0.65
valuesMethod · 0.45
useMethod · 0.45
limitMethod · 0.45
whereMethod · 0.45
fromMethod · 0.45
selectMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected