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/app/src/routes/auth/callback.ts | |
| parent | 5d12cadba7d03ca25becd5942cb8a959be1ddf00 (diff) | |
| download | opencode-f19586cebd77a4d2092e6ff66fb184a1366a9ce4.tar.gz opencode-f19586cebd77a4d2092e6ff66fb184a1366a9ce4.zip | |
fix anthropic console auth (#2049)
Diffstat (limited to 'cloud/app/src/routes/auth/callback.ts')
| -rw-r--r-- | cloud/app/src/routes/auth/callback.ts | 36 |
1 files changed, 36 insertions, 0 deletions
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, + } +} |
