Add launchable

This commit is contained in:
usernames122
2025-10-23 20:58:19 +02:00
parent 300bb16e5e
commit d9d5460856
27 changed files with 1743 additions and 85 deletions

36
js/core/Auth.js Normal file
View File

@@ -0,0 +1,36 @@
export class Auth {
constructor(baseUrl = "http://localhost:5000") {
this.baseUrl = baseUrl;
}
/**
* Verify a session token against the fake auth API.
* Returns the user ID if valid, or null if invalid.
*/
async verifySessionToken(token) {
try {
const res = await fetch(`${this.baseUrl}/api/verify/${encodeURIComponent(token)}`);
if (!res.ok) return null;
const data = await res.json();
return data.id ?? null;
} catch (err) {
console.warn("[Auth] verifySessionToken error:", err);
return null;
}
}
/**
* Look up the user's display name by ID.
*/
async getUserNameById(id) {
try {
const res = await fetch(`${this.baseUrl}/api/users`);
if (!res.ok) return "Unknown";
const data = await res.json();
return data[id] ?? `User${id}`;
} catch (err) {
console.warn("[Auth] getUserNameById error:", err);
return `User${id}`;
}
}
}