MCPcopy
hub / github.com/lobehub/lobehub / getAuthAndServer

Function getAuthAndServer

apps/cli/src/api/client.ts:19–55  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17let _toolsClient: ToolsTrpcClient | undefined;
18
19async function getAuthAndServer() {
20 // LOBEHUB_JWT + LOBEHUB_SERVER env vars (used by server-side sandbox execution)
21 const envJwt = process.env.LOBEHUB_JWT;
22 if (envJwt) {
23 const serverUrl = resolveServerUrl();
24
25 return {
26 headers: { 'Oidc-Auth': envJwt },
27 serverUrl,
28 };
29 }
30
31 const envApiKey = process.env[CLI_API_KEY_ENV];
32 if (envApiKey) {
33 const serverUrl = resolveServerUrl();
34
35 return {
36 headers: { 'X-API-Key': envApiKey },
37 serverUrl,
38 };
39 }
40
41 const result = await getValidToken();
42 if (!result) {
43 log.error(
44 `No authentication found. Run 'lh login' (or 'npx -y @lobehub/cli login') first, or set ${CLI_API_KEY_ENV}.`,
45 );
46 process.exit(1);
47 }
48
49 const serverUrl = resolveServerUrl();
50
51 return {
52 headers: { 'Oidc-Auth': result.credentials.accessToken },
53 serverUrl,
54 };
55}
56
57/**
58 * Resolve the workspace scope for outbound tRPC calls.

Callers 2

getTrpcClientFunction · 0.85
getToolsTrpcClientFunction · 0.85

Calls 2

resolveServerUrlFunction · 0.90
getValidTokenFunction · 0.90

Tested by

no test coverage detected