From d5fc7c8ac70c2254669e72aa15483e9317e7c492 Mon Sep 17 00:00:00 2001 From: Brayo Date: Fri, 26 Jul 2024 15:58:20 +0300 Subject: [PATCH] fix: typing error --- src/firebase/data.ts | 11 +++++++++-- src/stores/apikey.ts | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/firebase/data.ts b/src/firebase/data.ts index b205407..537cf6e 100644 --- a/src/firebase/data.ts +++ b/src/firebase/data.ts @@ -125,12 +125,19 @@ export async function getApiKey(userId: string): Promise { } } -export async function rotateKey(userId: string): Promise { +interface ApiResponse { + apiKey: string; +} + +export async function rotateKey(userId: string): Promise { // invoke a callable function to rotate the user's api key // this function is defined in functions/src/index.ts const rotateApiKey = httpsCallable(functions, 'rotateApiKey') const key = rotateApiKey({ userId: userId }).then((result) => { - return result.data.apiKey + if (typeof result.data === 'object' && result.data !== null && 'apiKey' in result.data) { + return (result.data as ApiResponse).apiKey; + } + return undefined }).catch((error) => { console.error(error) }).finally(() => { diff --git a/src/stores/apikey.ts b/src/stores/apikey.ts index 8ff7c61..6701897 100644 --- a/src/stores/apikey.ts +++ b/src/stores/apikey.ts @@ -17,7 +17,7 @@ export const useApiKeyStore = defineStore('apikey', () => { const userId = useAuthStore().user!.uid rotateKeyCallable(userId).then((key) => { console.log('Key is now', key) - if (key != null) { + if (typeof key === 'string') { console.log('Rotated key to', key) apikey.value = key }