/** * @fileoverview Login Page Component for Rantii * @author retoor * @description User authentication page * @keywords login, page, auth, signin, authentication */ import { BaseComponent } from '../components/base-component.js'; class LoginPage extends BaseComponent { init() { this.render(); this.bindEvents(); } render() { const isLoggedIn = this.isLoggedIn(); const user = this.getCurrentUser(); this.addClass('page', 'login-page'); if (isLoggedIn) { this.setHtml(`

Logged in as ${user?.username || ''}

Want to use a different account?

`); } else { this.setHtml(`
`); } } bindEvents() { this.on(this, 'click', this.handleClick); this.on(this, 'login-success', this.handleLoginSuccess); } handleClick(e) { const backBtn = e.target.closest('.back-btn'); const logoutBtn = e.target.closest('.logout-btn'); const switchBtn = e.target.closest('.switch-btn'); const homeBtn = e.target.closest('.home-btn'); if (backBtn) { window.history.back(); } else if (logoutBtn) { this.getAuth()?.logout(); this.render(); } else if (switchBtn) { this.getAuth()?.logout(); this.render(); } else if (homeBtn) { this.getRouter()?.goHome(); } } handleLoginSuccess() { this.getRouter()?.goHome(); } } customElements.define('login-page', LoginPage); export { LoginPage };