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:
@@ -40,32 +40,39 @@ export const createAuth = (
|
||||
export const getCurrentUser = query({
|
||||
args: {},
|
||||
handler: async (ctx) => {
|
||||
const authUser = await authComponent.safeGetAuthUser(ctx);
|
||||
if (!authUser) {
|
||||
try {
|
||||
const authUser = await authComponent.safeGetAuthUser(ctx);
|
||||
if (!authUser) {
|
||||
return;
|
||||
}
|
||||
|
||||
const user = await ctx.db
|
||||
.query('usuarios')
|
||||
.withIndex('authId', (q) => q.eq('authId', authUser._id))
|
||||
.unique();
|
||||
|
||||
if (!user) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Buscar foto de perfil e role em paralelo para melhor performance
|
||||
const [fotoPerfilUrl, role] = await Promise.all([
|
||||
user.fotoPerfil ? ctx.storage.getUrl(user.fotoPerfil).catch(() => null) : Promise.resolve(null),
|
||||
user.roleId
|
||||
? ctx.db
|
||||
.query('roles')
|
||||
.withIndex('by_id', (q) => q.eq('_id', user.roleId))
|
||||
.unique()
|
||||
.catch(() => null)
|
||||
: Promise.resolve(null)
|
||||
]);
|
||||
|
||||
return { ...user, role: role || null, fotoPerfilUrl };
|
||||
} catch (error) {
|
||||
// Log do erro mas não falhar completamente - retornar null para permitir retry
|
||||
console.error('Erro ao buscar usuário atual:', error);
|
||||
return;
|
||||
}
|
||||
|
||||
const user = await ctx.db
|
||||
.query('usuarios')
|
||||
.withIndex('authId', (q) => q.eq('authId', authUser._id))
|
||||
.unique();
|
||||
|
||||
if (!user) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fotoPerfilUrl = user.fotoPerfil ? await ctx.storage.getUrl(user.fotoPerfil) : null;
|
||||
|
||||
if (!user.roleId) {
|
||||
return { ...user, role: null, fotoPerfilUrl };
|
||||
}
|
||||
|
||||
const role = await ctx.db
|
||||
.query('roles')
|
||||
.withIndex('by_id', (q) => q.eq('_id', user.roleId))
|
||||
.unique();
|
||||
|
||||
return { ...user, role, fotoPerfilUrl };
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user