fix(nav): corrige sistema de navegação pós-login e sincronização de URL
Causa raiz do login não navegar: getCurrentRole() retornava null quando vinculos.role era NULL no banco, fazendo isViewAllowed() retornar false e handleNavigate() falhar silenciosamente sem nenhum feedback. Fixes: - backend.ts: getCurrentRole usa workspace?.role || 'paciente' para garantir que nunca retorne null/undefined - App.tsx: onLoginSuccess usa setCurrentView+navigate diretamente, sem passar pela guarda de permissão (desnecessária pós-autenticação) - App.tsx: mount effect sempre chama navigate(currentView) para sincronizar a URL com a view real — antes só executava com hash vazio, deixando /#/login na URL ao recarregar com usuário autenticado - LoginView.tsx: remove spinner isInitializing de 3s que bloqueava o formulário em toda montagem do componente Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+7
-5
@@ -210,11 +210,11 @@ const App: React.FC = () => {
|
||||
document.documentElement.style.setProperty('--brand-color-soft', `${clinColor}11`);
|
||||
}, [clinColor]);
|
||||
|
||||
// On mount: if there's no hash yet, write the current view into the URL
|
||||
// On mount: always sync URL to match the actual current view.
|
||||
// This handles auth redirects (e.g. reload at /#/login while authenticated shows dashboard
|
||||
// but URL would stay /#/login without this call).
|
||||
useEffect(() => {
|
||||
if (!window.location.hash || window.location.hash === '#update_db') {
|
||||
navigate(currentView);
|
||||
}
|
||||
navigate(currentView);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
@@ -244,7 +244,9 @@ const App: React.FC = () => {
|
||||
default:
|
||||
return <LoginView onLoginSuccess={() => {
|
||||
const role = HybridBackend.getCurrentRole();
|
||||
handleNavigate(getDefaultViewForRole(role));
|
||||
const view = getDefaultViewForRole(role);
|
||||
setCurrentView(view);
|
||||
navigate(view);
|
||||
}} />;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user