1// login.js â UX amigável p/ sessão existente + troca de conta 2 3document.addEventListener('DOMContentLoaded', async () => { 4 const user = await MetricasHub.getCurrentUser({ useLegacyToken: false }); 5 if (user) { 6 const name = user.get('name') || user.get('email')?.split('@')[0] || 'Usuário'; 7 const msg = `Você já está conectado como "${name}".\n\nDeseja continuar com essa conta?`; 8 if (confirm(msg)) { 9 await MetricasHub.goToDestination(); 10 return; 11 } else { 12 // troca de conta: faz logout e mantém na tela de login 13 try { await Parse.User.logOut(); } catch {} 14 } 15 } 16}); 17 18// handler do submit do formulário de login 19document.getElementById('loginForm').addEventListener('submit', async (e) => { 20 e.preventDefault(); 21 22 const email = document.getElementById('email').value.trim(); 23 const password = document.getElementById('password').value; 24 25 try { 26 // se já houver um usuário atual, ofereça troca 27 const current = await MetricasHub.getCurrentUser({ useLegacyToken: false }); 28 if (current) { 29 const name = current.get('name') || current.get('email')?.split('@')[0] || 'Usuário'; 30 const ok = confirm( 31 `Você está conectado como "${name}".\n\nPara entrar com outra conta, é preciso sair. Prosseguir?` 32 ); 33 if (!ok) return; 34 await Parse.User.logOut(); 35 } 36 37 // aqui faz o login (use sua CF ou o SDK direto) 38 // Opção A: Cloud Function própria 39 // const result = await Parse.Cloud.run('loginUser', { email, password }); 40 // await Parse.User.become(result.sessionToken); 41 42 // Opção B: SDK direto (se tiver beforeLogin/locks no backend) 43 await Parse.User.logIn(email, password); 44 45 await MetricasHub.goToDestination(); 46 } catch (err) { 47 console.error('Erro no login:', err); 48 alert(err?.message || 'Não foi possÃvel entrar. Tente novamente.'); 49 } 50});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.