@@ -451,13 +451,20 @@ <h3>✅ Voto Autorizado!</h3>
451451 configurado : false
452452} ;
453453
454- // Inicialização
454+ // ✅ CORREÇÃO: Apenas esta linha foi modificada
455455document . addEventListener ( "DOMContentLoaded" , async function ( ) {
456456 const urlParams = new URLSearchParams ( window . location . search ) ;
457- electionId = urlParams . get ( 'id' ) ;
457+
458+ // ✅ CORREÇÃO: Pegar ID da eleição de 'eleicao' OU 'id'
459+ electionId = urlParams . get ( 'eleicao' ) || urlParams . get ( 'id' ) ;
460+
461+ console . log ( '🆔 ID da Eleição capturado:' , electionId ) ;
458462
459463 if ( electionId ) {
460464 await carregarInfoEleicao ( ) ;
465+ } else {
466+ console . error ( '❌ Nenhum ID de eleição encontrado na URL!' ) ;
467+ document . getElementById ( 'info-eleicao' ) . textContent = '❌ Erro: Nenhuma eleição especificada' ;
461468 }
462469
463470 carregarConfigAPI ( ) ;
@@ -581,7 +588,7 @@ <h3>✅ Voto Autorizado!</h3>
581588 }
582589
583590 } catch ( error ) {
584- console . error ( 'Erro ao carregar eleição:' , error ) ;
591+ console . error ( '❌ Erro ao carregar eleição:' , error ) ;
585592 document . getElementById ( 'info-eleicao' ) . textContent = 'Erro ao carregar eleição' ;
586593 }
587594}
@@ -1114,7 +1121,7 @@ <h3>✅ Voto Autorizado!</h3>
11141121// ========== FLUXO PRINCIPAL ==========
11151122
11161123function prosseguirParaProximaEtapa ( ) {
1117- if ( eleicaoAtual . tipo === 'presencial' ) {
1124+ if ( eleicaoAtual && eleicaoAtual . tipo === 'presencial' ) {
11181125 document . getElementById ( 'segunda-autorizacao' ) . style . display = 'block' ;
11191126 } else {
11201127 document . getElementById ( 'botao-autorizar' ) . style . display = 'block' ;
@@ -1138,7 +1145,7 @@ <h3>✅ Voto Autorizado!</h3>
11381145function autorizarVoto ( ) {
11391146 if ( ! dadosEleitorAtual ) return ;
11401147
1141- if ( eleicaoAtual . tipo === 'presencial' && ! segundaAutorizacaoAprovada ) {
1148+ if ( eleicaoAtual && eleicaoAtual . tipo === 'presencial' && ! segundaAutorizacaoAprovada ) {
11421149 alert ( 'Confirme a segunda autorização para voto presencial' ) ;
11431150 return ;
11441151 }
@@ -1149,7 +1156,7 @@ <h3>✅ Voto Autorizado!</h3>
11491156 dbAutorizacoes . put ( {
11501157 _id : token ,
11511158 electionId : electionId ,
1152- tipoEleicao : eleicaoAtual . tipo ,
1159+ tipoEleicao : eleicaoAtual ? eleicaoAtual . tipo : 'online' ,
11531160 metodoIdentificacao : dadosEleitorAtual . metodo ,
11541161 dadosEleitor : dadosEleitorAtual ,
11551162 segundaAutorizacao : segundaAutorizacaoAprovada ,
@@ -1160,7 +1167,7 @@ <h3>✅ Voto Autorizado!</h3>
11601167
11611168 document . getElementById ( 'codigo-autorizacao' ) . textContent = codigo ;
11621169
1163- if ( eleicaoAtual . tipo === 'presencial' ) {
1170+ if ( eleicaoAtual && eleicaoAtual . tipo === 'presencial' ) {
11641171 document . getElementById ( 'mensagem-autorizacao' ) . textContent = 'Dupla autorização confirmada!' ;
11651172 } else {
11661173 document . getElementById ( 'mensagem-autorizacao' ) . textContent = 'Autorização online confirmada!' ;
0 commit comments