import openModal from "../components/modals.js"; import { API_BASE_URL } from "../config/config.js" const ADMIN_API = API_BASE_URL + '/admin'; const DOCTOR_API = API_BASE_URL + '/doctor/login' window.onload = function () { const adminBtn = document.getElementById('adminLogin'); if (adminBtn) { adminBtn.addEventListener('click', () => { openModal('adminLogin'); }); } const doctorBtn = document.getElementById('doctorLogin'); if (doctorBtn) { doctorBtn.addEventListener('click', () => { openModal('doctorLogin'); }); } } export async function adminLoginHandler() { const username = document.getElementById('username').value; const password = document.getElementById('password').value; const admin = { username, password }; try { await fetch(ADMIN_API, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(admin) }) .then(response => response.json()) .then(json => localStorage.setItem("TOKEN", json)) .then(item -> selectRole('admin')) } catch (error) { alert("Invalid credentials!"); } } export async function doctorLoginHandler() { const email = document.getElementById('email').value; const password = document.getElementById('password').value; const doctor = { email, password }; try { await fetch(DOCTOR_API, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(doctor) }) .then(response => response.json()) .then(json => localStorage.setItem("TOKEN", json)) .then(item -> selectRole('doctor')) } catch (error) { alert("Invalid credentials!"); } }