eletrotupi / tcc/ commit / ba96371

frontend: allow to customize content type

Pedro Lucas Porcellis porcellis@eletrotupi.com · 5 months ago ba9637187a559806967edd09125f84fea8b33461 Browse files
Parents 7822d9e
Changed files
1
Additions
+2
Deletions
-1
frontend/lib/api.ts modified+2 -1
frontend/lib/api.ts
1 1
import * as SecureStore from 'expo-secure-store';
2 2

3 3
const API_BASE_URL = process.env.EXPO_PUBLIC_API_BASE_URL;
4 4
const TOKEN_KEY = process.env.EXPO_PUBLIC_TOKEN_KEY; // Gary B.B Coleman fucking slaps
5 5

52 52
  private async request<T>(
53 53
    endpoint: string,
54 54
    options: RequestInit = {}
55 55
  ): Promise<T> {
56 56
    const token = await this.getStoredToken();
57 +
    const isFormData = options.body instanceof FormData;
57 58

58 59
    const config: RequestInit = {
59 60
      ...options,
60 61
      headers: {
61 -
        'Content-Type': 'application/json',
62 62
        ...(token && { Authorization: `Bearer ${token}` }),
63 +
        ...(!isFormData && { 'Content-Type': 'application/json' }),
63 64
        ...options.headers,
64 65
      },
65 66
    };
66 67

67 68
    const response = await fetch(`${API_BASE_URL}${endpoint}`, config);
166 167
    })
167 168
  }
168 169
}
169 170

170 171
export const apiClient = new ApiClient();