KSvend Claude Opus 4.6 (1M context) commited on
Commit Β·
4f2f97a
1
Parent(s): cb5a414
feat: add auth header to API calls, add login and listJobs API functions
Browse filesCo-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- frontend/js/api.js +29 -0
frontend/js/api.js
CHANGED
|
@@ -12,6 +12,13 @@ const BASE = ''; // same-origin; empty string = relative to current host
|
|
| 12 |
* @returns {Promise<any>}
|
| 13 |
*/
|
| 14 |
async function apiFetch(path, opts = {}) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
const defaults = {
|
| 16 |
headers: { 'Content-Type': 'application/json', ...(opts.headers || {}) },
|
| 17 |
};
|
|
@@ -91,3 +98,25 @@ export function packageUrl(jobId) {
|
|
| 91 |
export function mapUrl(jobId, indicatorId) {
|
| 92 |
return `${BASE}/api/jobs/${jobId}/maps/${indicatorId}`;
|
| 93 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
* @returns {Promise<any>}
|
| 13 |
*/
|
| 14 |
async function apiFetch(path, opts = {}) {
|
| 15 |
+
const session = JSON.parse(sessionStorage.getItem('aperture_session') || 'null');
|
| 16 |
+
if (session) {
|
| 17 |
+
opts.headers = {
|
| 18 |
+
...opts.headers,
|
| 19 |
+
'Authorization': `Bearer ${session.email}:${session.token}`,
|
| 20 |
+
};
|
| 21 |
+
}
|
| 22 |
const defaults = {
|
| 23 |
headers: { 'Content-Type': 'application/json', ...(opts.headers || {}) },
|
| 24 |
};
|
|
|
|
| 98 |
export function mapUrl(jobId, indicatorId) {
|
| 99 |
return `${BASE}/api/jobs/${jobId}/maps/${indicatorId}`;
|
| 100 |
}
|
| 101 |
+
|
| 102 |
+
/* ββ Auth βββββββββββββββββββββββββββββββββββββββββββββββββ */
|
| 103 |
+
|
| 104 |
+
export async function requestMagicLink(email) {
|
| 105 |
+
return apiFetch('/api/auth/request', {
|
| 106 |
+
method: 'POST',
|
| 107 |
+
headers: { 'Content-Type': 'application/json' },
|
| 108 |
+
body: JSON.stringify({ email }),
|
| 109 |
+
});
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
export async function verifyToken(email, token) {
|
| 113 |
+
return apiFetch('/api/auth/verify', {
|
| 114 |
+
method: 'POST',
|
| 115 |
+
headers: { 'Content-Type': 'application/json' },
|
| 116 |
+
body: JSON.stringify({ email, token }),
|
| 117 |
+
});
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
export async function listJobs() {
|
| 121 |
+
return apiFetch('/api/jobs');
|
| 122 |
+
}
|