diff options
| author | Dax <[email protected]> | 2025-08-18 17:12:21 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-18 17:12:21 -0400 |
| commit | f19586cebd77a4d2092e6ff66fb184a1366a9ce4 (patch) | |
| tree | bc1c2f4dbd6e12ed0d4e058c80b16a8071d8f427 /cloud | |
| parent | 5d12cadba7d03ca25becd5942cb8a959be1ddf00 (diff) | |
| download | opencode-f19586cebd77a4d2092e6ff66fb184a1366a9ce4.tar.gz opencode-f19586cebd77a4d2092e6ff66fb184a1366a9ce4.zip | |
fix anthropic console auth (#2049)
Diffstat (limited to 'cloud')
| -rw-r--r-- | cloud/app/package.json | 1 | ||||
| -rw-r--r-- | cloud/app/src/context/auth.tsx | 28 | ||||
| -rw-r--r-- | cloud/app/src/routes/auth/authorize.ts | 7 | ||||
| -rw-r--r-- | cloud/app/src/routes/auth/callback.ts | 36 | ||||
| -rw-r--r-- | cloud/app/src/routes/index.tsx | 2 |
5 files changed, 73 insertions, 1 deletions
diff --git a/cloud/app/package.json b/cloud/app/package.json index 61b3522a7..ba6ab6427 100644 --- a/cloud/app/package.json +++ b/cloud/app/package.json @@ -9,6 +9,7 @@ }, "dependencies": { "@ibm/plex": "6.4.1", + "@openauthjs/openauth": "0.0.0-20250322224806", "@solidjs/meta": "^0.29.4", "@solidjs/router": "^0.15.0", "@solidjs/start": "^1.1.0", diff --git a/cloud/app/src/context/auth.tsx b/cloud/app/src/context/auth.tsx new file mode 100644 index 000000000..bec949568 --- /dev/null +++ b/cloud/app/src/context/auth.tsx @@ -0,0 +1,28 @@ +import { useSession } from "vinxi/http" +import { createClient } from "@openauthjs/openauth/client" + +export const AuthClient = createClient({ + clientID: "app", + issuer: "https://auth.dev.opencode.ai", +}) + +export interface AuthSession { + account: Record<string, { + id: string + email: string + }> + current?: string +} + +export function useAuthSession() { + "use server" + + return useSession<AuthSession>({ + password: "0".repeat(32), + name: "auth" + }) +} + + +export function AuthProvider() { +} diff --git a/cloud/app/src/routes/auth/authorize.ts b/cloud/app/src/routes/auth/authorize.ts new file mode 100644 index 000000000..166466ef8 --- /dev/null +++ b/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/cloud/app/src/routes/auth/callback.ts b/cloud/app/src/routes/auth/callback.ts new file mode 100644 index 000000000..a561c70d0 --- /dev/null +++ b/cloud/app/src/routes/auth/callback.ts @@ -0,0 +1,36 @@ +import type { APIEvent } from "@solidjs/start/server" +import { AuthClient, useAuthSession } from "~/context/auth" + +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 redirectURI = `${url.origin}${url.pathname}` + console.log({ + redirectURI, + code, + }) + 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 { + result, + } +} diff --git a/cloud/app/src/routes/index.tsx b/cloud/app/src/routes/index.tsx index 7c7eee13d..da4e23364 100644 --- a/cloud/app/src/routes/index.tsx +++ b/cloud/app/src/routes/index.tsx @@ -51,7 +51,7 @@ export default function Home() { <a href="/docs">Get Started</a> </div> <div data-slot="right"> - <button data-copy data-slot="command" data-command="curl -fsSL https://opencode.ai/install | bash"> + <button data-copy data-slot="command"> <span> <span>curl -fsSL </span> <span data-slot="protocol">https://</span> |
