Dax Raad 5 месяцев назад
Родитель
Сommit
2e16d685eb

+ 2 - 2
cloud/app/src/context/auth.ts

@@ -22,8 +22,8 @@ export const getActor = async (): Promise<Actor.Info> => {
   const auth = await useAuthSession()
   const auth = await useAuthSession()
   const splits = url.pathname.split("/").filter(Boolean)
   const splits = url.pathname.split("/").filter(Boolean)
   if (splits[0] !== "workspace") {
   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 {
       return {
         type: "account",
         type: "account",
         properties: {
         properties: {

+ 1 - 1
cloud/app/src/routes/auth/callback.ts

@@ -27,5 +27,5 @@ export async function GET(input: APIEvent) {
       current: id,
       current: id,
     }
     }
   })
   })
-  return redirect("/")
+  return redirect("/auth")
 }
 }

+ 13 - 0
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")
+  }
+}

+ 0 - 7
cloud/app/src/routes/auth/logout.ts

@@ -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)
-}

+ 1 - 5
cloud/app/src/routes/index.tsx

@@ -89,11 +89,7 @@ export default function Home() {
           </span>
           </span>
           <span data-slot="divider">&nbsp;/&nbsp;</span>
           <span data-slot="divider">&nbsp;/&nbsp;</span>
           <a
           <a
-            href={
-              workspaceId()
-                ? `/workspace/${workspaceId()}`
-                : "/auth/authorize"
-            }
+            href="/auth"
             target="_self"
             target="_self"
           >
           >
             Sign in
             Sign in

+ 3 - 3
cloud/app/src/routes/workspace.tsx

@@ -23,10 +23,10 @@ const logout = action(async () => {
   if (current)
   if (current)
     await auth.update((val) => {
     await auth.update((val) => {
       delete val.account[current]
       delete val.account[current]
+      const first = Object.keys(val.account)[0]
+      val.current = first
       return val
       return val
     })
     })
-
-  return redirect("/")
 })
 })
 
 
 export default function WorkspaceLayout(props: RouteSectionProps) {
 export default function WorkspaceLayout(props: RouteSectionProps) {
@@ -43,7 +43,7 @@ export default function WorkspaceLayout(props: RouteSectionProps) {
         </div>
         </div>
         <div data-slot="header-actions">
         <div data-slot="header-actions">
           <span>{userInfo()?.user.email}</span>
           <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>
             <button type="submit" formaction={logout}>Logout</button>
           </form>
           </form>
         </div>
         </div>