wip: zen
This commit is contained in:
@@ -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: {
|
||||||
|
|||||||
@@ -27,5 +27,5 @@ export async function GET(input: APIEvent) {
|
|||||||
current: id,
|
current: id,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return redirect("/")
|
return redirect("/auth")
|
||||||
}
|
}
|
||||||
|
|||||||
13
cloud/app/src/routes/auth/index.ts
Normal file
13
cloud/app/src/routes/auth/index.ts
Normal file
@@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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)
|
|
||||||
}
|
|
||||||
@@ -89,11 +89,7 @@ export default function Home() {
|
|||||||
</span>
|
</span>
|
||||||
<span data-slot="divider"> / </span>
|
<span data-slot="divider"> / </span>
|
||||||
<a
|
<a
|
||||||
href={
|
href="/auth"
|
||||||
workspaceId()
|
|
||||||
? `/workspace/${workspaceId()}`
|
|
||||||
: "/auth/authorize"
|
|
||||||
}
|
|
||||||
target="_self"
|
target="_self"
|
||||||
>
|
>
|
||||||
Sign in
|
Sign in
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user