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 }