summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-09-02 18:00:48 -0400
committerDax Raad <[email protected]>2025-09-02 18:00:48 -0400
commit2e16d685eb5b37e022e7cbd6d4f1ea6cc05f9620 (patch)
treee69988fdd16d0b16533f6abca22765af148939c5
parente544cccc70cc717d3780bb3ee8a046d8314cc3f2 (diff)
downloadopencode-2e16d685eb5b37e022e7cbd6d4f1ea6cc05f9620.tar.gz
opencode-2e16d685eb5b37e022e7cbd6d4f1ea6cc05f9620.zip
wip: zen
-rw-r--r--cloud/app/src/context/auth.ts4
-rw-r--r--cloud/app/src/routes/auth/callback.ts2
-rw-r--r--cloud/app/src/routes/auth/index.ts13
-rw-r--r--cloud/app/src/routes/auth/logout.ts7
-rw-r--r--cloud/app/src/routes/index.tsx6
-rw-r--r--cloud/app/src/routes/workspace.tsx6
6 files changed, 20 insertions, 18 deletions
diff --git a/cloud/app/src/context/auth.ts b/cloud/app/src/context/auth.ts
index e04ccdb05..5cf366ca4 100644
--- a/cloud/app/src/context/auth.ts
+++ b/cloud/app/src/context/auth.ts
@@ -22,8 +22,8 @@ export const getActor = async (): Promise<Actor.Info> => {
const auth = await useAuthSession()
const splits = url.pathname.split("/").filter(Boolean)
if (splits[0] !== "workspace") {
- if (auth.data.current) {
- const current = auth.data.account[auth.data.current]
+ const current = auth.data.account[auth.data.current ?? ""]
+ if (current) {
return {
type: "account",
properties: {
diff --git a/cloud/app/src/routes/auth/callback.ts b/cloud/app/src/routes/auth/callback.ts
index 4e38df07e..23025b54d 100644
--- a/cloud/app/src/routes/auth/callback.ts
+++ b/cloud/app/src/routes/auth/callback.ts
@@ -27,5 +27,5 @@ export async function GET(input: APIEvent) {
current: id,
}
})
- return redirect("/")
+ return redirect("/auth")
}
diff --git a/cloud/app/src/routes/auth/index.ts b/cloud/app/src/routes/auth/index.ts
new file mode 100644
index 000000000..308ae2d1d
--- /dev/null
+++ b/cloud/app/src/routes/auth/index.ts
@@ -0,0 +1,13 @@
+import { Account } from "@opencode/cloud-core/account.js"
+import { redirect } from "@solidjs/router"
+import type { APIEvent } from "@solidjs/start/server"
+import { withActor } from "~/context/auth.withActor"
+
+export async function GET(input: APIEvent) {
+ try {
+ const workspaces = await withActor(async () => Account.workspaces())
+ return redirect(`/workspace/${workspaces[0].id}`)
+ } catch {
+ return redirect("/auth/authorize")
+ }
+}
diff --git a/cloud/app/src/routes/auth/logout.ts b/cloud/app/src/routes/auth/logout.ts
deleted file mode 100644
index 166466ef8..000000000
--- a/cloud/app/src/routes/auth/logout.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import type { APIEvent } from "@solidjs/start/server"
-import { AuthClient } from "~/context/auth"
-
-export async function GET(input: APIEvent) {
- const result = await AuthClient.authorize(new URL("./callback", input.request.url).toString(), "code")
- return Response.redirect(result.url, 302)
-}
diff --git a/cloud/app/src/routes/index.tsx b/cloud/app/src/routes/index.tsx
index 4cc64feac..deb7be7e9 100644
--- a/cloud/app/src/routes/index.tsx
+++ b/cloud/app/src/routes/index.tsx
@@ -89,11 +89,7 @@ export default function Home() {
</span>
<span data-slot="divider">&nbsp;/&nbsp;</span>
<a
- href={
- workspaceId()
- ? `/workspace/${workspaceId()}`
- : "/auth/authorize"
- }
+ href="/auth"
target="_self"
>
Sign in
diff --git a/cloud/app/src/routes/workspace.tsx b/cloud/app/src/routes/workspace.tsx
index c8c05ef43..5149954fa 100644
--- a/cloud/app/src/routes/workspace.tsx
+++ b/cloud/app/src/routes/workspace.tsx
@@ -23,10 +23,10 @@ const logout = action(async () => {
if (current)
await auth.update((val) => {
delete val.account[current]
+ const first = Object.keys(val.account)[0]
+ val.current = first
return val
})
-
- return redirect("/")
})
export default function WorkspaceLayout(props: RouteSectionProps) {
@@ -43,7 +43,7 @@ export default function WorkspaceLayout(props: RouteSectionProps) {
</div>
<div data-slot="header-actions">
<span>{userInfo()?.user.email}</span>
- <form action={logout} method="post">
+ <form onSubmit={() => location.href = "/"} action={logout} method="post">
<button type="submit" formaction={logout}>Logout</button>
</form>
</div>