ciyidogan commited on
Commit
55339eb
·
verified ·
1 Parent(s): 3c3a7e4

Update flare-ui/src/app/services/api.service.ts

Browse files
flare-ui/src/app/services/api.service.ts CHANGED
@@ -210,11 +210,26 @@ export class ApiService {
210
  }
211
 
212
  private getAuthHeaders(): HttpHeaders {
213
- const token = this.authService.getToken();
214
- return new HttpHeaders({
215
- 'Authorization': `Bearer ${token}`,
216
- 'Content-Type': 'application/json'
217
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  }
219
 
220
  // ===================== User =====================
@@ -265,10 +280,27 @@ export class ApiService {
265
  }
266
 
267
  createProject(data: any): Observable<any> {
268
- return this.http.post(`${this.adminUrl}/projects`, data, {
269
- headers: this.getAuthHeaders()
270
- }).pipe(
271
- catchError(this.handleError)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
  );
273
  }
274
 
 
210
  }
211
 
212
  private getAuthHeaders(): HttpHeaders {
213
+ try {
214
+ const token = this.authService.getToken();
215
+ if (!token) {
216
+ console.warn('No auth token available');
217
+ // Token yoksa boş header dön veya login'e yönlendir
218
+ return new HttpHeaders({
219
+ 'Content-Type': 'application/json'
220
+ });
221
+ }
222
+
223
+ return new HttpHeaders({
224
+ 'Authorization': `Bearer ${token}`,
225
+ 'Content-Type': 'application/json'
226
+ });
227
+ } catch (error) {
228
+ console.error('Error getting auth headers:', error);
229
+ return new HttpHeaders({
230
+ 'Content-Type': 'application/json'
231
+ });
232
+ }
233
  }
234
 
235
  // ===================== User =====================
 
280
  }
281
 
282
  createProject(data: any): Observable<any> {
283
+ console.log('createProject called with data:', data);
284
+
285
+ let headers;
286
+ try {
287
+ headers = this.getAuthHeaders();
288
+ console.log('Headers obtained successfully');
289
+ } catch (error) {
290
+ console.error('Error getting headers:', error);
291
+ return throwError(() => ({ message: 'Authentication error' }));
292
+ }
293
+
294
+ console.log('Making POST request to:', `${this.adminUrl}/projects`);
295
+
296
+ return this.http.post(`${this.adminUrl}/projects`, data, { headers }).pipe(
297
+ tap(response => {
298
+ console.log('Project creation successful:', response);
299
+ }),
300
+ catchError(error => {
301
+ console.error('Project creation failed:', error);
302
+ return this.handleError(error);
303
+ })
304
  );
305
  }
306