frontend/lib: add method to update user
Pedro Lucas Porcellis porcellis@eletrotupi.com · 5 months ago
17207313f44cdecf0de608083d71bbfaabc87bf5 Browse filesParents
4ad3b1eChanged files
1
Additions
+10
Deletions
-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
6 6
export interface User {
7 7
id: number;
8 8
email: string;
9 9
firstName: string;
10 10
lastName?: string;
11 +
updatedAt: Date;
11 12
}
12 13
13 14
export interface AuthResponse {
14 15
token: string;
15 16
user: User;
17 +
}
18 +
19 +
export interface UserUpdateResponse {
20 +
user: User
16 21
}
17 22
18 23
class ApiClient {
19 24
private async getStoredToken(): Promise<string | null> {
20 25
try {
58 63
};
59 64
60 65
const response = await fetch(`${API_BASE_URL}${endpoint}`, config);
61 66
62 67
if (!response.ok) {
63 -
const error = await response.json().catch(() => ({ error: 'Network error' }));
68 +
const error = await response.json()
69 +
.catch(() => ({ error: 'Network error' }));
70 +
71 +
console.error("[API]: ", error, response.status)
72 +
64 73
throw new Error(error.error || `HTTP ${response.status}`);
65 74
}
66 75
67 76
return response.json();
68 77
}
132 141
})
133 142
}
134 143
}
135 144
136 145
export const apiClient = new ApiClient();