mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-25 11:44:22 +01:00
fix anthropic console auth (#2049)
This commit is contained in:
28
cloud/app/src/context/auth.tsx
Normal file
28
cloud/app/src/context/auth.tsx
Normal file
@@ -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() {
|
||||
}
|
||||
7
cloud/app/src/routes/auth/authorize.ts
Normal file
7
cloud/app/src/routes/auth/authorize.ts
Normal file
@@ -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)
|
||||
}
|
||||
36
cloud/app/src/routes/auth/callback.ts
Normal file
36
cloud/app/src/routes/auth/callback.ts
Normal file
@@ -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,
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user