import axios from "axios"; import type { AxiosResponse } from "axios"; import { clientRuntime, DESKTOP_SERVER_URL_CHANGED_EVENT } from "../runtime"; const authClient = axios.create({ baseURL: clientRuntime.apiBaseUrl(), timeout: 15000, }); export const refreshAuthClientBaseUrl = (): void => { authClient.defaults.baseURL = clientRuntime.apiBaseUrl(); }; if (typeof window !== "undefined") { window.addEventListener(DESKTOP_SERVER_URL_CHANGED_EVENT, refreshAuthClientBaseUrl); } export type ExtendResponse = { accessToken: string; expiresAt: string; }; export type LoginKeyResponse = { key_id: string; public_key: string; challenge: string; expires_at: string; }; export type EncryptedPasswordRequest = { key_id: string; challenge: string; ciphertext: string; }; export const extendToken = (token: string): Promise> => authClient.post( "/api/v1/auth/extend", {}, { headers: { Authorization: `Bearer ${token}`, }, } ); export const getLoginKey = (): Promise> => authClient.get("/api/v1/auth/login-key"); export default authClient;