/**
* OxiCloud Authentication JavaScript
* Handles login, registration, and admin setup
*/
import { getCsrfHeaders } from '../../core/csrf.js';
import { i18n } from '../../core/i18n.js';
/**
* @import {AuthResponse, RoleEnum, User} from '../../core/types.js'
*/
// API endpoints
const API_URL = '/api/auth';
const LOGIN_ENDPOINT = `${API_URL}/login`;
const REGISTER_ENDPOINT = `${API_URL}/register`;
const ME_ENDPOINT = `${API_URL}/me`;
const REFRESH_ENDPOINT = `${API_URL}/refresh`;
// Storage keys — tokens are now in HttpOnly cookies (set by server).
// Only non-sensitive display data is kept in localStorage.
const USER_DATA_KEY = 'oxicloud_user';
const LOCALE_KEY = 'oxicloud-locale';
const FIRST_RUN_KEY = 'oxicloud_first_run_completed';
/**
* Narrow a thrown value (TS unknown) to a displayable message string.
* Returns '' for non-Error throws so callers can fall back via `errMessage(e) || fallback`.
* @param {unknown} e
* @returns {string}
*/
function errMessage(e) {
return e instanceof Error ? e.message : '';
}
/**
* Read the value of an /