diff options
| author | Frank <[email protected]> | 2025-09-18 01:32:40 -0400 |
|---|---|---|
| committer | Frank <[email protected]> | 2025-09-18 01:32:40 -0400 |
| commit | fc4f281408c56ab12db571a470456212a479edf5 (patch) | |
| tree | 309d23b0c497bc61af6f8e650a6036fa41d7cbdb /packages/cloud/app/src/routes/auth | |
| parent | f8c4f713a5b48892899d0ac195c3470ab7ef764c (diff) | |
| download | opencode-fc4f281408c56ab12db571a470456212a479edf5.tar.gz opencode-fc4f281408c56ab12db571a470456212a479edf5.zip | |
wip: zen
Diffstat (limited to 'packages/cloud/app/src/routes/auth')
| -rw-r--r-- | packages/cloud/app/src/routes/auth/authorize.ts | 7 | ||||
| -rw-r--r-- | packages/cloud/app/src/routes/auth/callback.ts | 31 | ||||
| -rw-r--r-- | packages/cloud/app/src/routes/auth/index.ts | 13 |
3 files changed, 51 insertions, 0 deletions
diff --git a/packages/cloud/app/src/routes/auth/authorize.ts b/packages/cloud/app/src/routes/auth/authorize.ts new file mode 100644 index 000000000..166466ef8 --- /dev/null +++ b/packages/cloud/app/src/routes/auth/authorize.ts @@ -0,0 +1,7 @@ +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/packages/cloud/app/src/routes/auth/callback.ts b/packages/cloud/app/src/routes/auth/callback.ts new file mode 100644 index 000000000..23025b54d --- /dev/null +++ b/packages/cloud/app/src/routes/auth/callback.ts @@ -0,0 +1,31 @@ +import { redirect } from "@solidjs/router" +import type { APIEvent } from "@solidjs/start/server" +import { AuthClient } from "~/context/auth" +import { useAuthSession } from "~/context/auth.session" + +export async function GET(input: APIEvent) { + const url = new URL(input.request.url) + const code = url.searchParams.get("code") + if (!code) throw new Error("No code found") + const result = await AuthClient.exchange(code, `${url.origin}${url.pathname}`) + if (result.err) { + throw new Error(result.err.message) + } + const decoded = AuthClient.decode(result.tokens.access, {} as any) + if (decoded.err) throw new Error(decoded.err.message) + const session = await useAuthSession() + const id = decoded.subject.properties.accountID + await session.update((value) => { + return { + ...value, + account: { + [id]: { + id, + email: decoded.subject.properties.email, + }, + }, + current: id, + } + }) + return redirect("/auth") +} diff --git a/packages/cloud/app/src/routes/auth/index.ts b/packages/cloud/app/src/routes/auth/index.ts new file mode 100644 index 000000000..308ae2d1d --- /dev/null +++ b/packages/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") + } +} |
