| <script> | |
| async function authFetch(url, options = {}) { | |
| const token = localStorage.getItem("jwt_token"); | |
| options.headers = { | |
| ...(options.headers || {}), | |
| "Authorization": "Bearer " + token, | |
| "Content-Type": "application/json" | |
| }; | |
| const response = await fetch(url, options); | |
| if (response.status === 401) { | |
| alert("Session expired. Please login again."); | |
| window.location.href = "/auth/login"; | |
| return; | |
| } | |
| return response.json(); | |
| } | |
| </script> | |