From f8e92f3c58a489c2efa2671c796a91cc04b7be3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?PontualTech=20/=20Karl=C3=A3o?= Date: Tue, 28 Apr 2026 09:13:37 -0300 Subject: [PATCH] fix(auth): cloudConfigured() reconhece login Google/email (sem token) v1.7.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug crítico: após login Google ou email, o app pedia pra logar DE NOVO toda vez que abria/fechava. E sync nunca iniciava. Causa: cloudConfigured() exigia state.cloud.token, mas no login Google/email a auth fica em state.auth.accessToken (JWT), não em state.cloud.token (que é o BOAT_TOKEN avançado). Resultado: cloudConfigured() retornava false → welcome screen sempre aparecia, rtConnect() nunca rodava, sync zero. Fix: - cloudConfigured() agora retorna true se tem state.auth.accessToken OU state.cloud.token (qualquer um dos dois) - maybeShowWelcome() reescrito pra checar autenticação real - Botão "Usar sem login (modo offline)" mais visível na welcome screen pra dar saída clara Co-Authored-By: Claude Opus 4.7 (1M context) --- app/diario-bordo.html | 19 +++++++++++++++---- mobile/android/app/build.gradle | 4 ++-- mobile/package.json | 2 +- server/public/index.html | 19 +++++++++++++++---- server/src/index.js | 2 +- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/app/diario-bordo.html b/app/diario-bordo.html index 89f2b28..24da53d 100644 --- a/app/diario-bordo.html +++ b/app/diario-bordo.html @@ -2531,7 +2531,7 @@ Hora: {HORA} - + @@ -4248,7 +4248,13 @@ function saveContactsConfig(){ let heartbeatInterval=null; let cloudAutoSyncTimeout=null; -function cloudConfigured(){return state.cloud&&state.cloud.url&&state.cloud.token} +function cloudConfigured(){ + if(!state.cloud||!state.cloud.url)return false; + // Auth: tem JWT (login Google/email) OU BOAT_TOKEN (avançado/legacy) + if(state.auth&&state.auth.accessToken)return true; + if(state.cloud.token)return true; + return false; +} function cloudUrl(path){return state.cloud.url.replace(/\/$/,'')+path} async function cloudFetch(path,opts={}){ @@ -4274,9 +4280,14 @@ const GOOGLE_CLIENT_ID_FRONTEND='989184529532-uceun7l7a12e63fdrkilnh8vml0v0lv4.a function maybeShowWelcome(){ const ws=document.getElementById('welcome-screen'); if(!ws)return; - // Mostra se: nuvem não configurada E user não está logado E nunca dispensou + // Mostra welcome SE: não tem auth nem token configurado E não dispensou explicitamente const dismissed=localStorage.getItem('shivao_welcome_dismissed')==='1'; - const needsSetup=(!cloudConfigured()||!state.auth)&&!dismissed; + // Logado via JWT (Google/email) → não precisa welcome + const hasJwtAuth=state.auth&&state.auth.accessToken; + // Conectado via BOAT_TOKEN avançado → não precisa welcome + const hasBoatToken=state.cloud&&state.cloud.token; + const isAuthenticated=hasJwtAuth||hasBoatToken; + const needsSetup=!isAuthenticated&&!dismissed; ws.style.display=needsSetup?'flex':'none'; // Se mostrar, prepara o Google Sign-In quando carregar if(needsSetup&&window.google?.accounts?.id){ diff --git a/mobile/android/app/build.gradle b/mobile/android/app/build.gradle index 42376e7..4c0fecf 100644 --- a/mobile/android/app/build.gradle +++ b/mobile/android/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "br.com.pontualtech.shivao" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 10 - versionName "1.7.0" + versionCode 11 + versionName "1.7.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" aaptOptions { // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps. diff --git a/mobile/package.json b/mobile/package.json index 5aa9d0e..1357e3a 100644 --- a/mobile/package.json +++ b/mobile/package.json @@ -1,6 +1,6 @@ { "name": "shivao-mobile", - "version": "1.7.0", + "version": "1.7.1", "description": "Shivao app nativo (Capacitor wrapper Android/iOS)", "main": "index.js", "type": "module", diff --git a/server/public/index.html b/server/public/index.html index 89f2b28..24da53d 100644 --- a/server/public/index.html +++ b/server/public/index.html @@ -2531,7 +2531,7 @@ Hora: {HORA} - + @@ -4248,7 +4248,13 @@ function saveContactsConfig(){ let heartbeatInterval=null; let cloudAutoSyncTimeout=null; -function cloudConfigured(){return state.cloud&&state.cloud.url&&state.cloud.token} +function cloudConfigured(){ + if(!state.cloud||!state.cloud.url)return false; + // Auth: tem JWT (login Google/email) OU BOAT_TOKEN (avançado/legacy) + if(state.auth&&state.auth.accessToken)return true; + if(state.cloud.token)return true; + return false; +} function cloudUrl(path){return state.cloud.url.replace(/\/$/,'')+path} async function cloudFetch(path,opts={}){ @@ -4274,9 +4280,14 @@ const GOOGLE_CLIENT_ID_FRONTEND='989184529532-uceun7l7a12e63fdrkilnh8vml0v0lv4.a function maybeShowWelcome(){ const ws=document.getElementById('welcome-screen'); if(!ws)return; - // Mostra se: nuvem não configurada E user não está logado E nunca dispensou + // Mostra welcome SE: não tem auth nem token configurado E não dispensou explicitamente const dismissed=localStorage.getItem('shivao_welcome_dismissed')==='1'; - const needsSetup=(!cloudConfigured()||!state.auth)&&!dismissed; + // Logado via JWT (Google/email) → não precisa welcome + const hasJwtAuth=state.auth&&state.auth.accessToken; + // Conectado via BOAT_TOKEN avançado → não precisa welcome + const hasBoatToken=state.cloud&&state.cloud.token; + const isAuthenticated=hasJwtAuth||hasBoatToken; + const needsSetup=!isAuthenticated&&!dismissed; ws.style.display=needsSetup?'flex':'none'; // Se mostrar, prepara o Google Sign-In quando carregar if(needsSetup&&window.google?.accounts?.id){ diff --git a/server/src/index.js b/server/src/index.js index 38a3f0d..e88e4fa 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -347,7 +347,7 @@ app.get('/.well-known/assetlinks.json', (req, res) => { }); // Atalho: /apk redireciona pra última APK release no Forgejo -const LATEST_APK_URL = 'https://git.pontualtech.work/karlao/shivao-projeto/releases/download/v1.7.0/Shivao-v1.7.0.apk'; +const LATEST_APK_URL = 'https://git.pontualtech.work/karlao/shivao-projeto/releases/download/v1.7.1/Shivao-v1.7.1.apk'; app.get('/apk', (req, res) => res.redirect(302, LATEST_APK_URL)); // Página A4 imprimível com QR Code + instruções (cola no barco/marina)