fix(frontend): check both 'auth_token' and 'token' in api client

Unblocks API calls by correctly reading the token saved by auth.ts
This commit is contained in:
Tiago Yamamoto 2025-12-24 17:16:54 -03:00
parent 41d7d9ee70
commit c1650fd1a4

View file

@ -16,7 +16,8 @@ function logCrudAction(action: string, entity: string, details?: any) {
* Generic API Request Wrapper
*/
async function apiRequest<T>(endpoint: string, options: RequestInit = {}): Promise<T> {
const token = localStorage.getItem("token");
// Token can be stored as 'auth_token' (from auth.ts login) or 'token' (legacy)
const token = localStorage.getItem("auth_token") || localStorage.getItem("token");
const headers = {
"Content-Type": "application/json",
...(token ? { Authorization: `Bearer ${token}` } : {}),