refactor: optimize login attempt logging in Sidebar component to avoid timeouts by deferring user retrieval; enhance MessageList component with improved message processing and state management to prevent unnecessary re-renders
This commit is contained in:
@@ -193,11 +193,10 @@
|
||||
if (result.data) {
|
||||
// Registrar tentativa de login bem-sucedida
|
||||
// Fazer de forma assíncrona para não bloquear o login
|
||||
// Não tentamos buscar getCurrentUser aqui porque pode causar timeout
|
||||
// O useQuery no componente já busca o usuário automaticamente quando a sessão estiver pronta
|
||||
(async () => {
|
||||
try {
|
||||
// Aguardar um pouco para o usuário ser sincronizado no Convex
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
|
||||
// Tentar obter GPS se já estiver disponível (não esperar)
|
||||
let localizacaoGPS: any = {};
|
||||
try {
|
||||
@@ -209,40 +208,21 @@
|
||||
// Ignorar se GPS não estiver pronto
|
||||
}
|
||||
|
||||
// Buscar o usuário no Convex usando getCurrentUser
|
||||
const usuario = await convexClient.query(api.auth.getCurrentUser, {});
|
||||
|
||||
if (usuario && usuario._id) {
|
||||
await convexClient.mutation(api.logsLogin.registrarTentativaLogin, {
|
||||
usuarioId: usuario._id,
|
||||
matriculaOuEmail: matricula.trim(),
|
||||
sucesso: true,
|
||||
userAgent: userAgent,
|
||||
ipAddress: ipPublico,
|
||||
latitudeGPS: localizacaoGPS.latitude,
|
||||
longitudeGPS: localizacaoGPS.longitude,
|
||||
precisaoGPS: localizacaoGPS.precisao,
|
||||
enderecoGPS: localizacaoGPS.endereco,
|
||||
cidadeGPS: localizacaoGPS.cidade,
|
||||
estadoGPS: localizacaoGPS.estado,
|
||||
paisGPS: localizacaoGPS.pais
|
||||
});
|
||||
} else {
|
||||
// Se não encontrou o usuário, registrar sem usuarioId (será atualizado depois)
|
||||
await convexClient.mutation(api.logsLogin.registrarTentativaLogin, {
|
||||
matriculaOuEmail: matricula.trim(),
|
||||
sucesso: true,
|
||||
userAgent: userAgent,
|
||||
ipAddress: ipPublico,
|
||||
latitudeGPS: localizacaoGPS.latitude,
|
||||
longitudeGPS: localizacaoGPS.longitude,
|
||||
precisaoGPS: localizacaoGPS.precisao,
|
||||
enderecoGPS: localizacaoGPS.endereco,
|
||||
cidadeGPS: localizacaoGPS.cidade,
|
||||
estadoGPS: localizacaoGPS.estado,
|
||||
paisGPS: localizacaoGPS.pais
|
||||
});
|
||||
}
|
||||
// Registrar log sem usuarioId - será atualizado depois quando o usuário estiver disponível
|
||||
// Isso evita timeouts que ocorrem quando tentamos buscar getCurrentUser imediatamente após login
|
||||
await convexClient.mutation(api.logsLogin.registrarTentativaLogin, {
|
||||
matriculaOuEmail: matricula.trim(),
|
||||
sucesso: true,
|
||||
userAgent: userAgent,
|
||||
ipAddress: ipPublico,
|
||||
latitudeGPS: localizacaoGPS.latitude,
|
||||
longitudeGPS: localizacaoGPS.longitude,
|
||||
precisaoGPS: localizacaoGPS.precisao,
|
||||
enderecoGPS: localizacaoGPS.endereco,
|
||||
cidadeGPS: localizacaoGPS.cidade,
|
||||
estadoGPS: localizacaoGPS.estado,
|
||||
paisGPS: localizacaoGPS.pais
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Erro ao registrar tentativa de login:', err);
|
||||
// Não bloquear o login se houver erro ao registrar
|
||||
|
||||
Reference in New Issue
Block a user