Added Login Screen

This commit is contained in:
2025-10-22 00:02:25 +03:00
parent b5a7c31277
commit 859396fea9
8 changed files with 324 additions and 71 deletions

View File

@@ -1 +1,20 @@
export const API = import.meta.env.VITE_API || "http://localhost:3001";
export const API = import.meta.env.VITE_API || "http://localhost:3001";
// 🔐 Ortak kimlik doğrulama başlığı (token varsa ekler)
export function authHeaders() {
const token = localStorage.getItem("token");
return token ? { Authorization: `Bearer ${token}` } : {};
}
// 🔧 Yardımcı fetch (otomatik token ekler, hata durumunda logout)
export async function apiFetch(path, options = {}) {
const headers = { ...(options.headers || {}), ...authHeaders() };
const res = await fetch(`${API}${path}`, { ...options, headers });
// Token süresi dolmuşsa veya yanlışsa kullanıcıyı çıkışa yönlendir
if (res.status === 401) {
localStorage.removeItem("token");
window.location.reload();
}
return res;
}