const AUTH_KEY = 'aetherforge_auth';

export function getStoredAuth(): string | null {
  try {
    return sessionStorage.getItem(AUTH_KEY);
  } catch {
    return null;
  }
}

export function setStoredAuth(username: string, password: string) {
  const token = btoa(`${username}:${password}`);
  sessionStorage.setItem(AUTH_KEY, token);
}

export function clearStoredAuth() {
  sessionStorage.removeItem(AUTH_KEY);
}

export function authHeaders(): Record<string, string> {
  const token = getStoredAuth();
  if (!token) return {};
  return { Authorization: `Basic ${token}` };
}
