()
| 95 | } |
| 96 | |
| 97 | async 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 | } |
no test coverage detected