apiKeyService.ts 599 B

12345678910111213141516171819202122232425
  1. import { apiClient } from './apiClient';
  2. export interface ApiKeyInfo {
  3. apiKey: string;
  4. }
  5. class ApiKeyService {
  6. /**
  7. * Get current user's API key (creates one if not exists)
  8. */
  9. async getApiKey(): Promise<ApiKeyInfo> {
  10. const response = await apiClient.get<ApiKeyInfo>('/users/api-key');
  11. return response.data;
  12. }
  13. /**
  14. * Regenerate API key for current user
  15. */
  16. async regenerateApiKey(): Promise<ApiKeyInfo> {
  17. const response = await apiClient.post<ApiKeyInfo>('/users/api-key/rotate');
  18. return response.data;
  19. }
  20. }
  21. export const apiKeyService = new ApiKeyService();