diff options
| author | Frank <[email protected]> | 2025-10-17 00:26:00 -0400 |
|---|---|---|
| committer | Frank <[email protected]> | 2025-10-17 00:26:00 -0400 |
| commit | a590b32a100472f2ed1673660c5235006a87d86b (patch) | |
| tree | cd9823c535edc6f0ed3cd013127e966cfc4d0ea3 | |
| parent | 5f7bba11fddd24f01c7be81870320dfe54672a3b (diff) | |
| download | opencode-a590b32a100472f2ed1673660c5235006a87d86b.tar.gz opencode-a590b32a100472f2ed1673660c5235006a87d86b.zip | |
wip: zen
| -rw-r--r-- | packages/console/app/src/component/header.tsx | 6 | ||||
| -rw-r--r-- | packages/console/app/src/routes/auth/index.ts | 26 | ||||
| -rw-r--r-- | packages/console/app/src/routes/workspace/common.tsx | 33 | ||||
| -rw-r--r-- | packages/console/app/src/routes/zen/index.tsx | 14 |
4 files changed, 38 insertions, 41 deletions
diff --git a/packages/console/app/src/component/header.tsx b/packages/console/app/src/component/header.tsx index d6b3e2a43..29b35bfa4 100644 --- a/packages/console/app/src/component/header.tsx +++ b/packages/console/app/src/component/header.tsx @@ -4,11 +4,9 @@ import { A, createAsync } from "@solidjs/router" import { createMemo, Match, Show, Switch } from "solid-js" import { createStore } from "solid-js/store" import { github } from "~/lib/github" -import { queryIsLoggedIn } from "~/routes/workspace/common" export function Header(props: { zen?: boolean }) { const githubData = createAsync(() => github()) - const isLoggedIn = createAsync(() => queryIsLoggedIn()) const starCount = createMemo(() => githubData()?.stars ? new Intl.NumberFormat("en-US", { @@ -41,7 +39,7 @@ export function Header(props: { zen?: boolean }) { <li> <Switch> <Match when={props.zen}> - <a href="/auth">{isLoggedIn() ? "Workspace" : "Login"}</a> + <a href="/auth">Login</a> </Match> <Match when={!props.zen}> <A href="/zen">Zen</A> @@ -112,7 +110,7 @@ export function Header(props: { zen?: boolean }) { <li> <Switch> <Match when={props.zen}> - <a href="/auth">{isLoggedIn() ? "Workspace" : "Login"}</a> + <a href="/auth">Login</a> </Match> <Match when={!props.zen}> <A href="/zen">Zen</A> diff --git a/packages/console/app/src/routes/auth/index.ts b/packages/console/app/src/routes/auth/index.ts index 63430b77f..5b49db157 100644 --- a/packages/console/app/src/routes/auth/index.ts +++ b/packages/console/app/src/routes/auth/index.ts @@ -1,32 +1,10 @@ -import { Actor } from "@opencode-ai/console-core/actor.js" -import { and, Database, desc, eq, isNull } from "@opencode-ai/console-core/drizzle/index.js" -import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js" -import { WorkspaceTable } from "@opencode-ai/console-core/schema/workspace.sql.js" import { redirect } from "@solidjs/router" import type { APIEvent } from "@solidjs/start/server" -import { withActor } from "~/context/auth.withActor" +import { getLastSeenWorkspaceID } from "../workspace/common" export async function GET(input: APIEvent) { try { - const workspaceID = await withActor(async () => { - const actor = Actor.assert("account") - return Database.transaction(async (tx) => - tx - .select({ id: WorkspaceTable.id }) - .from(UserTable) - .innerJoin(WorkspaceTable, eq(UserTable.workspaceID, WorkspaceTable.id)) - .where( - and( - eq(UserTable.accountID, actor.properties.accountID), - isNull(UserTable.timeDeleted), - isNull(WorkspaceTable.timeDeleted), - ), - ) - .orderBy(desc(UserTable.timeSeen)) - .limit(1) - .then((x) => x[0]?.id), - ) - }) + const workspaceID = await getLastSeenWorkspaceID() return redirect(`/workspace/${workspaceID}`) } catch { return redirect("/auth/authorize") diff --git a/packages/console/app/src/routes/workspace/common.tsx b/packages/console/app/src/routes/workspace/common.tsx index 625693223..03a40b579 100644 --- a/packages/console/app/src/routes/workspace/common.tsx +++ b/packages/console/app/src/routes/workspace/common.tsx @@ -3,6 +3,10 @@ import { Actor } from "@opencode-ai/console-core/actor.js" import { action, query } from "@solidjs/router" import { withActor } from "~/context/auth.withActor" import { Billing } from "@opencode-ai/console-core/billing.js" +import { User } from "@opencode-ai/console-core/user.js" +import { and, Database, desc, eq, isNull } from "@opencode-ai/console-core/drizzle/index.js" +import { WorkspaceTable } from "@opencode-ai/console-core/schema/workspace.sql.js" +import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js" export function formatDateForTable(date: Date) { const options: Intl.DateTimeFormatOptions = { @@ -30,17 +34,28 @@ export function formatDateUTC(date: Date) { return date.toLocaleDateString("en-US", options) } -export const queryIsLoggedIn = query(async () => { +export async function getLastSeenWorkspaceID() { "use server" - return withActor(() => { - try { - Actor.assert("account") - return true - } catch { - return false - } + return withActor(async () => { + const actor = Actor.assert("account") + return Database.use(async (tx) => + tx + .select({ id: WorkspaceTable.id }) + .from(UserTable) + .innerJoin(WorkspaceTable, eq(UserTable.workspaceID, WorkspaceTable.id)) + .where( + and( + eq(UserTable.accountID, actor.properties.accountID), + isNull(UserTable.timeDeleted), + isNull(WorkspaceTable.timeDeleted), + ), + ) + .orderBy(desc(UserTable.timeSeen)) + .limit(1) + .then((x) => x[0]?.id), + ) }) -}, "isLoggedIn.get") +} export const querySessionInfo = query(async (workspaceID: string) => { "use server" diff --git a/packages/console/app/src/routes/zen/index.tsx b/packages/console/app/src/routes/zen/index.tsx index 080070d4f..08e58e160 100644 --- a/packages/console/app/src/routes/zen/index.tsx +++ b/packages/console/app/src/routes/zen/index.tsx @@ -1,5 +1,5 @@ import "./index.css" -import { createAsync } from "@solidjs/router" +import { createAsync, query, redirect } from "@solidjs/router" import { Title, Meta, Link } from "@solidjs/meta" import { HttpHeader } from "@solidjs/start" import zenLogoLight from "../../asset/zen-ornate-light.svg" @@ -16,10 +16,16 @@ import { Faq } from "~/component/faq" import { Legal } from "~/component/legal" import { Footer } from "~/component/footer" import { Header } from "~/component/header" -import { queryIsLoggedIn } from "~/routes/workspace/common" +import { getLastSeenWorkspaceID } from "../workspace/common" + +const checkLoggedIn = query(async () => { + "use server" + const workspaceID = await getLastSeenWorkspaceID() + if (workspaceID) throw redirect(`/workspace/${workspaceID}`) +}, "checkLoggedIn.get") export default function Home() { - const isLoggedIn = createAsync(() => queryIsLoggedIn()) + createAsync(() => checkLoggedIn()) return ( <main data-page="zen"> <HttpHeader name="Cache-Control" value="public, max-age=1, s-maxage=3600, stale-while-revalidate=86400" /> @@ -105,7 +111,7 @@ export default function Home() { </div> </div> <a href="/auth"> - <span>{isLoggedIn() ? "Go to workspace " : "Get started with Zen "}</span> + <span>Get started with Zen </span> <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M6.5 12L17 12M13 16.5L17.5 12L13 7.5" |
