Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[functions] Add options parameter to useHttpsCallable #314

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ The `useHttpsCallable` hook takes the following parameters:

- `functions`: `functions.Functions` instance for your Firebase app
- `name`: A `string` representing the name of the function to call
- `options`: (optional) `Object` with the following parameters:
- `timeout`: (optional) `number` Time in milliseconds after which to cancel if there is no response
- `limitedUseAppCheckTokens`: (optional) `boolean` If set to true, uses limited-use App Check token for callable function requests from this instance of `Functions`

Returns:

Expand Down
9 changes: 6 additions & 3 deletions functions/useHttpsCallable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Functions,
httpsCallable,
HttpsCallableOptions,
HttpsCallableResult,
} from 'firebase/functions';
import { useCallback, useState } from 'react';
Expand All @@ -20,7 +21,8 @@ export type HttpsCallableHook<

export default <RequestData = unknown, ResponseData = unknown>(
functions: Functions,
name: string
name: string,
options?: HttpsCallableOptions,
): HttpsCallableHook<RequestData, ResponseData> => {
const [error, setError] = useState<Error>();
const [loading, setLoading] = useState<boolean>(false);
Expand All @@ -31,7 +33,8 @@ export default <RequestData = unknown, ResponseData = unknown>(
): Promise<HttpsCallableResult<ResponseData> | undefined> => {
const callable = httpsCallable<RequestData, ResponseData>(
functions,
name
name,
options,
);
setLoading(true);
setError(undefined);
Expand All @@ -43,7 +46,7 @@ export default <RequestData = unknown, ResponseData = unknown>(
setLoading(false);
}
},
[functions, name]
[functions, name, options]
);

return [callCallable, loading, error] as const;
Expand Down