Skip to content

Commit 140dd3d

Browse files
authored
Merge pull request #863 from SlideRuleEarth/carlos-dev4
Prompt user to enter new credentials for google base layer if needed …
2 parents 9e52568 + 23aa6f3 commit 140dd3d

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

web-client/src/App.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import SrClearCache from '@/components/SrClearCache.vue'
1818
import { useSysConfigStore } from '@/stores/sysConfigStore'
1919
import { useJwtStore } from '@/stores/SrJWTStore'
2020
import { useAuthDialogStore } from '@/stores/authDialogStore'
21+
import { useGoogleApiKeyStore } from '@/stores/googleApiKeyStore'
2122
import SrJsonDisplayDialog from '@/components/SrJsonDisplayDialog.vue'
23+
import SrGoogleApiKeyInput from '@/components/SrGoogleApiKeyInput.vue'
2224
import InputText from 'primevue/inputtext'
2325
import Password from 'primevue/password'
2426
import Button from 'primevue/button'
@@ -39,6 +41,7 @@ const tourStore = useTourStore()
3941
const sysConfigStore = useSysConfigStore()
4042
const jwtStore = useJwtStore()
4143
const authDialogStore = useAuthDialogStore()
44+
const googleApiKeyStore = useGoogleApiKeyStore()
4245
const route = useRoute()
4346
4447
// Global login dialog state
@@ -864,6 +867,17 @@ async function handleLongTourButtonClick() {
864867
</div>
865868
</form>
866869
</Dialog>
870+
871+
<!-- Google API Key Dialog -->
872+
<Dialog
873+
v-model:visible="googleApiKeyStore.dialogVisible"
874+
header="Google API Key Required"
875+
:modal="true"
876+
:closable="true"
877+
style="width: 600px; max-width: 95vw"
878+
>
879+
<SrGoogleApiKeyInput />
880+
</Dialog>
867881
</div>
868882
</template>
869883

web-client/src/components/SrAnalysisMap.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import SrBaseLayerControl from '@/components/SrBaseLayerControl.vue'
4141
import SrGraticuleControl from '@/components/SrGraticuleControl.vue'
4242
import { findSrViewKey, srViews } from '@/composables/SrViews'
4343
import { addLayersForCurrentView } from '@/composables/SrLayers'
44+
import { useGoogleApiKeyStore } from '@/stores/googleApiKeyStore'
4445
import { useFieldNameStore } from '@/stores/fieldNameStore'
4546
import { selectSrViewForExtent } from '@/utils/srViewSelector'
4647
import SrLocationFinder from '@/components/SrLocationFinder.vue'
@@ -93,6 +94,7 @@ const atlChartFilterStore = useAtlChartFilterStore()
9394
const activeTabStore = useActiveTabStore()
9495
const fieldNameStore = useFieldNameStore()
9596
const debugStore = useDebugStore()
97+
const googleApiKeyStore = useGoogleApiKeyStore()
9698
const controls = ref([])
9799
const tooltipRef = ref<InstanceType<typeof SrCustomTooltip> | null>(null)
98100
const showContextMenu = ref(false)
@@ -285,6 +287,17 @@ watch(
285287
}
286288
)
287289
290+
// Watch for Google API key validation to refresh the map
291+
watch(
292+
() => googleApiKeyStore.refreshTrigger,
293+
async (newValue, oldValue) => {
294+
if (newValue > oldValue) {
295+
logger.debug('Google API key validated, refreshing map')
296+
await updateAnalysisMapView('Google API key validated')
297+
}
298+
}
299+
)
300+
288301
onMounted(async () => {
289302
logger.debug('SrAnalysisMap onMounted', { selectedReqId: props.selectedReqId })
290303
await fieldNameStore.loadMetaForReqId(props.selectedReqId) // async but don't await

web-client/src/components/SrGoogleApiKeyInput.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ async function validateAndSave() {
8888
life: 3000
8989
})
9090
inputKey.value = ''
91+
googleApiKeyStore.hideDialog()
9192
} else {
9293
const errorType = googleApiKeyStore.getLastError()
9394
toast.add({

web-client/src/composables/SrLayers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -984,19 +984,19 @@ export const getLayer = (
984984

985985
if (!googleApiKeyStore.hasValidKey()) {
986986
logger.warn('[SrLayers] Google layer requested but no valid API key configured')
987-
// Return undefined - the UI will prompt the user for an API key
987+
// Prompt the user to configure their API key
988+
googleApiKeyStore.showDialog()
988989
return undefined
989990
}
990991

991992
const apiKey = googleApiKeyStore.getApiKey()
992993
const sessionToken = googleApiKeyStore.getSessionToken()
993994

994995
// Session should exist from when the key was validated
995-
// If not, the user needs to re-enter their key in Settings
996+
// If not, the user needs to re-enter their key
996997
if (!sessionToken) {
997-
logger.error(
998-
'[SrLayers] No Google session token available - please re-validate your API key in Settings'
999-
)
998+
logger.error('[SrLayers] No Google session token available - prompting for API key')
999+
googleApiKeyStore.showDialog()
10001000
return undefined
10011001
}
10021002

web-client/src/stores/googleApiKeyStore.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export const useGoogleApiKeyStore = defineStore('googleApiKey', {
1818
validationStatus: 'unknown' as ValidationStatus,
1919
lastError: null as ErrorType,
2020
sessionToken: null as string | null,
21-
sessionExpiry: null as number | null
21+
sessionExpiry: null as number | null,
22+
dialogVisible: false,
23+
refreshTrigger: 0
2224
}),
2325
persist: {
2426
// Use sessionStorage - persists within tab until closed
@@ -107,6 +109,7 @@ export const useGoogleApiKeyStore = defineStore('googleApiKey', {
107109
this.setSessionToken(data.session, 23 * 60 * 60)
108110
}
109111
logger.debug('API key validated successfully')
112+
this.triggerMapRefresh()
110113
return true
111114
} else {
112115
const errorData = await response.json().catch(() => ({}))
@@ -194,6 +197,16 @@ export const useGoogleApiKeyStore = defineStore('googleApiKey', {
194197
})
195198
return false
196199
}
200+
},
201+
triggerMapRefresh() {
202+
this.refreshTrigger++
203+
logger.debug('Map refresh triggered', { refreshTrigger: this.refreshTrigger })
204+
},
205+
showDialog() {
206+
this.dialogVisible = true
207+
},
208+
hideDialog() {
209+
this.dialogVisible = false
197210
}
198211
}
199212
})

0 commit comments

Comments
 (0)