The best way to control Claude Code, Codex and more from any computer or phone

main
ts 52 lines 1.86 KB
Raw
1 import * as Binding from "alchemy/Binding";
2 import type { RuntimeContext } from "alchemy/RuntimeContext";
3 import * as Effect from "effect/Effect";
4 import * as Layer from "effect/Layer";
5 import type { Auth } from "./Auth.ts";
6 import { backendEnvKey, backendString, bindBackendEnvironment } from "./BackendConnection.ts";
7
8 export interface ConnectAuthClient {
9 /** Public managed Better Auth URL for the standard Neon auth client. */
10 baseUrl: Effect.Effect<string, never, RuntimeContext>;
11 /** Public JWKS endpoint. Verify signature, issuer, audience and expiry with an established JWT library. */
12 jwksUrl: Effect.Effect<string, never, RuntimeContext>;
13 }
14
15 /**
16 * Bind managed Auth's public connection configuration. This does not create an
17 * admin credential, verify a JWT, or replace the standard Neon Auth SDK.
18 *
19 * ### Connect managed authentication
20 * **Example:** Obtain configuration inside a Function
21 * ```typescript
22 * const authClient = yield* Neon.ConnectAuth(auth);
23 * // In the request handler:
24 * const baseUrl = yield* authClient.baseUrl;
25 * ```
26 *
27 * @binding
28 * @product Auth
29 */
30 export interface ConnectAuth extends Binding.Service<
31 ConnectAuth,
32 "Neon.ConnectAuth",
33 (auth: Auth) => Effect.Effect<ConnectAuthClient>
34 > {}
35 export const ConnectAuth = Binding.Service<ConnectAuth>("Neon.ConnectAuth");
36
37 /** Bind public Auth URLs on Neon Functions, Workers, Lambda and other env hosts. */
38 export const ConnectAuthHttp = Layer.succeed(
39 ConnectAuth,
40 Effect.fn(function* (auth: Auth) {
41 const baseUrl = backendEnvKey(auth.FQN, "AUTH_URL");
42 const jwksUrl = backendEnvKey(auth.FQN, "AUTH_JWKS_URL");
43 yield* bindBackendEnvironment(`Neon.ConnectAuth:${auth.FQN}`, {
44 [baseUrl]: auth.baseUrl,
45 [jwksUrl]: auth.jwksUrl,
46 });
47 return {
48 baseUrl: backendString(baseUrl),
49 jwksUrl: backendString(jwksUrl),
50 } satisfies ConnectAuthClient;
51 }),
52 );