cleanup semicolon from js

This commit is contained in:
2026-01-31 15:43:58 +01:00
parent f919079f69
commit 640e7a3a4f
22 changed files with 1258 additions and 1269 deletions

View File

@@ -5,14 +5,14 @@
* User remembers only their UUID
*/
import { directus } from './directus.js';
import { directus } from './directus.js'
const AUTH_DOMAIN = 'dgray.io';
const AUTH_DOMAIN = 'dgray.io'
class AuthService {
constructor() {
this.currentUser = null;
this.listeners = new Set();
this.currentUser = null
this.listeners = new Set()
}
/**
@@ -22,15 +22,15 @@ class AuthService {
generateUuid() {
// Use native if available (secure contexts)
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
return crypto.randomUUID();
return crypto.randomUUID()
}
// Fallback for non-secure contexts
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
const r = Math.random() * 16 | 0
const v = c === 'x' ? r : (r & 0x3 | 0x8)
return v.toString(16)
})
}
/**
@@ -39,7 +39,7 @@ class AuthService {
* @returns {string} Fake email address
*/
uuidToEmail(uuid) {
return `${uuid}@${AUTH_DOMAIN}`;
return `${uuid}@${AUTH_DOMAIN}`
}
/**
@@ -47,14 +47,14 @@ class AuthService {
* @returns {Promise<{uuid: string, success: boolean, error?: string}>}
*/
async createAccount() {
const uuid = this.generateUuid();
const email = this.uuidToEmail(uuid);
const uuid = this.generateUuid()
const email = this.uuidToEmail(uuid)
try {
await directus.register(email, uuid);
await directus.register(email, uuid)
// Try auto-login (may fail if verification required)
const loginResult = await this.login(uuid);
const loginResult = await this.login(uuid)
if (!loginResult.success) {
// Registration worked but login failed (verification pending)
@@ -63,17 +63,17 @@ class AuthService {
success: true,
pendingVerification: true,
message: 'Account created. Login may require activation.'
};
}
}
return { uuid, success: true };
return { uuid, success: true }
} catch (error) {
console.error('Registration failed:', error);
console.error('Registration failed:', error)
return {
uuid: null,
success: false,
error: error.message || 'Registration failed'
};
}
}
}
@@ -83,21 +83,21 @@ class AuthService {
* @returns {Promise<{success: boolean, error?: string}>}
*/
async login(uuid) {
const email = this.uuidToEmail(uuid);
const email = this.uuidToEmail(uuid)
try {
await directus.login(email, uuid);
this.currentUser = await directus.getCurrentUser();
this.notifyListeners();
this.storeUuid(uuid);
await directus.login(email, uuid)
this.currentUser = await directus.getCurrentUser()
this.notifyListeners()
this.storeUuid(uuid)
return { success: true };
return { success: true }
} catch (error) {
console.error('Login failed:', error);
console.error('Login failed:', error)
return {
success: false,
error: error.message || 'Invalid UUID'
};
}
}
}
@@ -106,14 +106,14 @@ class AuthService {
*/
async logout() {
try {
await directus.logout();
await directus.logout()
} catch (e) {
// Ignore errors
}
this.currentUser = null;
this.clearStoredUuid();
this.notifyListeners();
this.currentUser = null
this.clearStoredUuid()
this.notifyListeners()
}
/**
@@ -121,7 +121,7 @@ class AuthService {
* @returns {boolean}
*/
isLoggedIn() {
return directus.isAuthenticated();
return directus.isAuthenticated()
}
/**
@@ -129,17 +129,17 @@ class AuthService {
* @returns {Promise<Object|null>}
*/
async getUser() {
if (!this.isLoggedIn()) return null;
if (!this.isLoggedIn()) return null
if (!this.currentUser) {
try {
this.currentUser = await directus.getCurrentUser();
this.currentUser = await directus.getCurrentUser()
} catch (e) {
return null;
return null
}
}
return this.currentUser;
return this.currentUser
}
/**
@@ -148,7 +148,7 @@ class AuthService {
* @param {string} uuid
*/
storeUuid(uuid) {
localStorage.setItem('dgray_uuid', uuid);
localStorage.setItem('dgray_uuid', uuid)
}
/**
@@ -156,14 +156,14 @@ class AuthService {
* @returns {string|null}
*/
getStoredUuid() {
return localStorage.getItem('dgray_uuid');
return localStorage.getItem('dgray_uuid')
}
/**
* Clears stored UUID
*/
clearStoredUuid() {
localStorage.removeItem('dgray_uuid');
localStorage.removeItem('dgray_uuid')
}
/**
@@ -172,15 +172,15 @@ class AuthService {
* @returns {Function} Unsubscribe function
*/
subscribe(callback) {
this.listeners.add(callback);
return () => this.listeners.delete(callback);
this.listeners.add(callback)
return () => this.listeners.delete(callback)
}
/**
* Notifies all listeners of auth state change
*/
notifyListeners() {
this.listeners.forEach(cb => cb(this.isLoggedIn(), this.currentUser));
this.listeners.forEach(cb => cb(this.isLoggedIn(), this.currentUser))
}
/**
@@ -189,16 +189,16 @@ class AuthService {
async tryRestoreSession() {
if (directus.isAuthenticated()) {
try {
this.currentUser = await directus.getCurrentUser();
this.notifyListeners();
return true;
this.currentUser = await directus.getCurrentUser()
this.notifyListeners()
return true
} catch (e) {
return false;
return false
}
}
return false;
return false
}
}
export const auth = new AuthService();
export default auth;
export const auth = new AuthService()
export default auth