import { AuthService } from '../../services/authService';
/**
* Creates and displays the login screen UI
* Shown when user is not authenticated
*/
export function showLoginScreen(): void {
const container = document.querySelector('#levelSelect');
if (!container) {
console.error('Level select container not found');
return;
}
container.innerHTML = `
Space Combat VR
Welcome, pilot! Authentication required to access your mission data and track your progress across the galaxy.
Secured by Auth0
`;
// Attach login handler
const loginBtn = document.getElementById('loginBtn');
if (loginBtn) {
loginBtn.addEventListener('click', async () => {
loginBtn.textContent = 'Redirecting...';
loginBtn.setAttribute('disabled', 'true');
const authService = AuthService.getInstance();
await authService.login();
});
}
}
/**
* Updates the user profile display in the header
* Shows username and logout button when authenticated, or login button when not
* @param username - The username to display, or null to show login button
*/
export function updateUserProfile(username: string | null): void {
const profileContainer = document.getElementById('userProfile');
if (!profileContainer) return;
if (username) {
// User is authenticated - show profile and logout
profileContainer.className = 'user-profile';
profileContainer.innerHTML = `
Welcome, ${username}
`;
const logoutBtn = document.getElementById('logoutBtn');
if (logoutBtn) {
logoutBtn.addEventListener('click', async () => {
const authService = AuthService.getInstance();
await authService.logout();
});
}
} else {
// User not authenticated - show login/signup button
profileContainer.className = '';
profileContainer.innerHTML = `
`;
const loginBtn = document.getElementById('loginBtn');
if (loginBtn) {
loginBtn.addEventListener('click', async () => {
const authService = AuthService.getInstance();
await authService.login();
});
}
}
}