MCPcopy
hub / github.com/lingodotdev/lingo.dev / tryGetEmail

Function tryGetEmail

packages/compiler/src/utils/observability.ts:97–128  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

95}
96
97async function tryGetEmail(): Promise<string | null> {
98 const rc = getRc();
99 const apiKey = process.env.LINGODOTDEV_API_KEY || rc?.auth?.apiKey;
100 const apiUrl =
101 process.env.LINGODOTDEV_API_URL ||
102 rc?.auth?.apiUrl ||
103 "https://api.lingo.dev";
104
105 if (!apiKey) {
106 return null;
107 }
108
109 try {
110 const res = await fetch(`${apiUrl}/users/me`, {
111 method: "GET",
112 headers: {
113 "X-API-Key": apiKey,
114 "Content-Type": "application/json",
115 },
116 });
117 if (res.ok) {
118 const payload = await res.json();
119 if (payload?.email) {
120 return payload.email;
121 }
122 }
123 } catch (err) {
124 // ignore
125 }
126
127 return null;
128}

Callers 1

getDistinctIdFunction · 0.70

Calls 1

getRcFunction · 0.90

Tested by

no test coverage detected