Compare commits
No commits in common. "c4ae9c67893790d6f55c5e914b036f45a34e69ce" and "accb64ca5e932b46c2caf78e2be46ccd676ebad0" have entirely different histories.
c4ae9c6789
...
accb64ca5e
@ -112,7 +112,7 @@ export default function HospitalLayout({ children }: HospitalLayoutProps) {
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50 flex">
|
||||
{/* Sidebar */}
|
||||
{/* Sidebar */}
|
||||
<div
|
||||
className={`bg-white border-r border-gray-200 transition-all duration-300 ${sidebarCollapsed ? "w-16" : "w-64"} h-screen flex flex-col`}
|
||||
>
|
||||
|
||||
@ -1,64 +0,0 @@
|
||||
|
||||
// váriaveis básicas
|
||||
const BASE_URL = "https://yuanqfswhberkoevtmfr.supabase.co";
|
||||
const API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inl1YW5xZnN3aGJlcmtvZXZ0bWZyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTQ5NTQzNjksImV4cCI6MjA3MDUzMDM2OX0.g8Fm4XAvtX46zifBZnYVH4tVuQkqUH6Ia9CXQj4DztQ";
|
||||
var tempToken;
|
||||
|
||||
async function login() {
|
||||
const response = await fetch("https://yuanqfswhberkoevtmfr.supabase.co/auth/v1/token?grant_type=password", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"apikey": API_KEY, // valor fixo
|
||||
},
|
||||
body: JSON.stringify({ email: "hugo@popcode.com.br", password: "hdoria" }),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
console.log("Resposta da API:", data);
|
||||
console.log("Token:", data.access_token);
|
||||
// salvar o token do usuário
|
||||
//localStorage.setItem("token", data.access_token);
|
||||
tempToken = data.access_token
|
||||
|
||||
return data;
|
||||
}
|
||||
await login()
|
||||
|
||||
async function request(endpoint, options = {}) {
|
||||
//const token = localStorage.getItem("token"); // token do usuário, salvo no login
|
||||
const token = tempToken;
|
||||
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
"apikey": API_KEY, // obrigatório sempre
|
||||
...(token ? { Authorization: `Bearer ${token}` } : {}), // obrigatório em todas EXCETO login
|
||||
...options.headers,
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch(`${BASE_URL}${endpoint}`, {
|
||||
...options,
|
||||
headers,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Erro HTTP: ${response.status}`);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error("Erro na requisição:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export const api = {
|
||||
get: (endpoint) => request(endpoint, { method: "GET" }),
|
||||
post: (endpoint, body) =>
|
||||
request(endpoint, { method: "POST", body: JSON.stringify(body) }),
|
||||
patch: (endpoint, body) =>
|
||||
request(endpoint, { method: "PATCH", body: JSON.stringify(body) }),
|
||||
delete: (endpoint) => request(endpoint, { method: "DELETE" }),
|
||||
};
|
||||
@ -1,9 +0,0 @@
|
||||
import { api } from "./api.mjs";
|
||||
|
||||
export const patientsService = {
|
||||
list: () => api.get("/rest/v1/patients"),
|
||||
getById: (id) => api.get(`/rest/v1/patients/${id}`),
|
||||
create: (data) => api.post("/rest/v1/patients", data),
|
||||
update: (id, data) => api.patch(`/rest/v1/patients/${id}`, data),
|
||||
delete: (id) => api.delete(`/rest/v1/patients/${id}`),
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user