Skip to content

Commit

Permalink
fix: typing error
Browse files Browse the repository at this point in the history
  • Loading branch information
brayo-pip committed Jul 26, 2024
1 parent f444f43 commit d5fc7c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/firebase/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,19 @@ export async function getApiKey(userId: string): Promise<string | null> {
}
}

export async function rotateKey(userId: string): Promise<string | null> {
interface ApiResponse {
apiKey: string;
}

export async function rotateKey(userId: string): Promise<string | null | void> {
// 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(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/stores/apikey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit d5fc7c8

Please sign in to comment.