MCPcopy Index your code
hub / github.com/anomalyco/opencode / GET

Function GET

packages/console/app/src/routes/auth/[...callback].ts:8–46  ·  view source on GitHub ↗
(input: APIEvent)

Source from the content-addressed store, hash-verified

6import { localeFromRequest, route } from "~/lib/language"
7
8export async function GET(input: APIEvent) {
9 const url = new URL(input.request.url)
10 const locale = localeFromRequest(input.request)
11 const dict = i18n(locale)
12
13 try {
14 const code = url.searchParams.get("code")
15 if (!code) throw new Error(dict["auth.callback.error.codeMissing"])
16 const result = await AuthClient.exchange(code, `${url.origin}${url.pathname}`)
17 if (result.err) throw new Error(result.err.message)
18 const decoded = AuthClient.decode(result.tokens.access, {} as any)
19 if (decoded.err) throw new Error(decoded.err.message)
20 const session = await useAuthSession()
21 const id = decoded.subject.properties.accountID
22 await session.update((value) => {
23 return {
24 ...value,
25 account: {
26 ...value.account,
27 [id]: {
28 id,
29 email: decoded.subject.properties.email,
30 },
31 },
32 current: id,
33 }
34 })
35 const next = url.pathname === "/auth/callback" ? "/auth" : url.pathname.replace("/auth/callback", "")
36 return redirect(route(locale, next))
37 } catch (e: any) {
38 return new Response(
39 JSON.stringify({
40 error: e.message,
41 cause: Object.fromEntries(url.searchParams.entries()),
42 }),
43 { status: 500 },
44 )
45 }
46}

Callers

nothing calls this directly

Calls 7

localeFromRequestFunction · 0.90
i18nFunction · 0.90
useAuthSessionFunction · 0.90
routeFunction · 0.90
redirectFunction · 0.85
getMethod · 0.65
updateMethod · 0.65

Tested by

no test coverage detected