PersonaAI

Sign in to your account

Forgot password?
Or continue with

Don't have an account? Sign up

const passwordInput = document.getElementById('password'); const togglePasswordBtn = document.getElementById('togglePassword'); const eyeIcon = document.getElementById('eyeIcon'); let isPasswordVisible = false; togglePasswordBtn.addEventListener('click', () => { isPasswordVisible = !isPasswordVisible; passwordInput.type = isPasswordVisible ? 'text' : 'password'; eyeIcon.textContent = isPasswordVisible ? '🙈' : '👁️'; }); document.getElementById('loginForm').addEventListener('submit', async (e) => { e.preventDefault(); const submitBtn = document.getElementById('submitBtn'); const originalText = submitBtn.textContent; submitBtn.disabled = true; submitBtn.textContent = 'Signing in...'; const email = document.getElementById('email').value; const password = document.getElementById('password').value; const remember = document.getElementById('remember').checked; try { const response = await fetch('/api/v1/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, password }) }); const data = await response.json(); if (response.ok) { setToken(data.access_token); if (data.refresh_token) { localStorage.setItem(AUTH_KEYS.REFRESH_TOKEN, data.refresh_token); } if (data.user) { setUserInfo(data.user); } window.location.href = '/profile'; } else { // Handle 422 validation errors (FastAPI returns array format) let errorMsg = 'Login failed. Please try again.'; if (data.detail) { errorMsg = Array.isArray(data.detail) ? data.detail.map(e => e.msg || JSON.stringify(e)).join(', ') : data.detail; } alert(errorMsg); submitBtn.disabled = false; submitBtn.textContent = originalText; } } catch (error) { alert('An error occurred. Please try again.'); submitBtn.disabled = false; submitBtn.textContent = originalText; } }); document.getElementById('googleLoginBtn').addEventListener('click', () => { window.location.href = '/api/v1/auth/oauth/google'; });