MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / validateAuthToken

Function validateAuthToken

apps/extension/src/shared/auth.ts:191–225  ·  view source on GitHub ↗
({
  apiBaseUrl,
  fetch,
  signal,
  token,
}: ValidateAuthTokenOptions)

Source from the content-addressed store, hash-verified

189};
190
191export const validateAuthToken = async ({
192 apiBaseUrl,
193 fetch,
194 signal,
195 token,
196}: ValidateAuthTokenOptions): Promise<TokenValidationResult> => {
197 const requestInit: RequestInit = {
198 headers: { Authorization: `Bearer ${token}` },
199 ...(signal === undefined ? {} : { signal }),
200 };
201 const response = await fetch(`${trimTrailingSlash(apiBaseUrl)}/api/user`, requestInit);
202
203 if (response.status === 401 || response.status === 403) {
204 return { status: 'invalid' };
205 }
206
207 if (!response.ok) {
208 return { status: 'error' };
209 }
210
211 const data: unknown = await response.json();
212 const parsed = userResponseSchema.safeParse(data);
213
214 if (!parsed.success) {
215 return { auth: { token, userEmail: undefined }, status: 'valid' };
216 }
217
218 return {
219 auth: {
220 token,
221 userEmail: parsed.data.google_user_email,
222 },
223 status: 'valid',
224 };
225};

Callers 2

AppFunction · 0.90
auth.test.tsFile · 0.90

Calls 3

fetchFunction · 0.70
trimTrailingSlashFunction · 0.70
jsonMethod · 0.65

Tested by

no test coverage detected