Skip to content

Commit 410f40d

Browse files
committed
refactor: use react-query-subscriptions for useAuthIdToken
1 parent 589daf1 commit 410f40d

34 files changed

+726
-153
lines changed

.eslintignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
**/dist/**/*.*
2-
**/coverage/**/*.*
2+
**/coverage/**/*.*

.opensource/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"pages": [],
66
"related": ["firebase/firebase-js-sdk", "tannerlinsley/react-query"],
77
"tabs": []
8-
}
8+
}

.prettierignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
**/lib/**
2+
node_modules
3+
*.js
4+
*.json
5+
*.md
6+
*.yaml
7+
coverage

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
<br />
1111

1212
React Query Firebase provides a set of easy to use hooks for handling asynchronous tasks with Firebase in your React application.
13+
1314
## Why should I use React Query Firebase?
1415

1516
- **Backed by React Query** - Unlike other solutions, hooks are built on top of [React Query](https://react-query.tanstack.com) which takes care of complex challenges
16-
such as caching, automatic refetching, realtime data subscriptions, pagination & infinite queries, mutations, SSR Support, data selectors, side effect handlers and more. You also get [DevTool](https://react-query.tanstack.com/devtools)
17-
support out of the box!
17+
such as caching, automatic refetching, realtime data subscriptions, pagination & infinite queries, mutations, SSR Support, data selectors, side effect handlers and more. You also get [DevTool](https://react-query.tanstack.com/devtools)
18+
support out of the box!
1819
- **Un-opinionated** - You provide the Query Keys, Configuration & Firebase instances, allowing for full control over how your data is integrated and cached. You can also roll it alongside any existing Firebase usage.
19-
- **Performant & Efficient** - Whether your queries are one-off or realtime, the library is designed to be performant and efficient. Data fetching is handled via [Queries](https://react-query.tanstack.com/guides/queries) and
20-
[Query Keys](https://react-query.tanstack.com/guides/query-keys), meaning components can share data throughout your application without needless database reads.
21-
- **Mutations** - Sign a user in, delete a document, run a transaction, log an event... React Query Firebase takes care of that for you via [Mutations](https://react-query.tanstack.com/guides/mutations), allowing you to focus
22-
on your application and not managing complex local loading & error states.
20+
- **Performant & Efficient** - Whether your queries are one-off or realtime, the library is designed to be performant and efficient. Data fetching is handled via [Queries](https://react-query.tanstack.com/guides/queries) and
21+
[Query Keys](https://react-query.tanstack.com/guides/query-keys), meaning components can share data throughout your application without needless database reads.
22+
- **Mutations** - Sign a user in, delete a document, run a transaction, log an event... React Query Firebase takes care of that for you via [Mutations](https://react-query.tanstack.com/guides/mutations), allowing you to focus
23+
on your application and not managing complex local loading & error states.
2324
- **Fully Typed** - The library is built with and has full compatibility with TypeScript.
2425

2526
> **Note**: The library supports the Firebase JS SDK v9 - [learn more about it here](https://firebase.googleblog.com/2021/08/the-new-firebase-js-sdk-now-ga.html)!

docs/analytics/typescript.mdx

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Hooks for integrating with Firebase Analytics.
55

66
# TypeScript
77

8-
The library exposes the various type interfaces for logging events to Analytics.
8+
The library exposes the various type interfaces for logging events to Analytics.
99
The interface map below outlines the various event names and their interfaces:
1010

1111
```ts
@@ -41,6 +41,6 @@ mutation.mutate({
4141
params: {
4242
firebase_screen: "Search",
4343
firebase_screen_class: "SearchPage",
44-
}
45-
})
46-
```
44+
},
45+
});
46+
```

docs/auth/actions.mdx

+7-8
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ const mutation = useAuthUnlink();
487487

488488
mutation.mutate({
489489
user: auth.currentUser,
490-
providerId: 'google.com',
490+
providerId: "google.com",
491491
});
492492
```
493493

@@ -515,7 +515,7 @@ const mutation = useAuthUpdateEmail();
515515

516516
mutation.mutate({
517517
user: auth.currentUser,
518-
newEmail: '[email protected]',
518+
newEmail: "[email protected]",
519519
});
520520
```
521521

@@ -530,7 +530,7 @@ const mutation = useAuthUpdatePassword();
530530

531531
mutation.mutate({
532532
user: auth.currentUser,
533-
newPassword: '...',
533+
newPassword: "...",
534534
});
535535
```
536536

@@ -561,8 +561,8 @@ const mutation = useAuthUpdateProfile();
561561

562562
mutation.mutate({
563563
user: auth.currentUser,
564-
displayName: '...', // optional
565-
photoURL: 'https://...', // optional
564+
displayName: "...", // optional
565+
photoURL: "https://...", // optional
566566
});
567567
```
568568

@@ -577,7 +577,7 @@ const mutation = useAuthVerifyBeforeUpdateEmail();
577577

578578
mutation.mutate({
579579
user: auth.currentUser,
580-
newEmail: '[email protected]',
580+
newEmail: "[email protected]",
581581
actionCodeSettings: {}, // optional
582582
});
583583
```
@@ -591,6 +591,5 @@ Checks a password reset code sent to the user by email or other out-of-band mech
591591
```js
592592
const mutation = useAuthVerifyPasswordResetCode(auth);
593593

594-
mutation.mutate('oobCode');
594+
mutation.mutate("oobCode");
595595
```
596-

docs/auth/auth-state.mdx

+4-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function App() {
3535
```
3636

3737
Anytime your users state changes, the hooks data will be updated allowing you to reactively handle updates
38-
within your application. If the user is authenticated, the hook returns the
38+
within your application. If the user is authenticated, the hook returns the
3939
[`User`](https://firebase.google.com/docs/reference/js/auth.user) interface, otherwise it's `null`.
4040

4141
## Sharing a Query Key
@@ -86,13 +86,11 @@ side effects with ease:
8686
const user = useAuthUser(["user"], auth, {
8787
onSuccess(user) {
8888
if (user) {
89-
console.log('User is authenticated!', user);
89+
console.log("User is authenticated!", user);
9090
}
9191
},
9292
onError(error) {
93-
console.error('Failed to subscribe to users authentication state!');
94-
}
93+
console.error("Failed to subscribe to users authentication state!");
94+
},
9595
});
9696
```
97-
98-

docs/auth/id-token.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ useAuthIdToken(["token"], auth, {
8686
if (result) {
8787
return result.token;
8888
} else {
89-
return '';
89+
return "";
9090
}
9191
},
9292
});

docs/auth/index.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Hooks for integrating with Authentication.
55

66
# Authentication
77

8-
The `@react-query-firebase/auth` package provides hooks subscribing to a authentication state and triggering
8+
The `@react-query-firebase/auth` package provides hooks subscribing to a authentication state and triggering
99
authentication requests.
1010

1111
## Installation

docs/comparison.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ and stale data with zero configuration. It also provides tools such as DevTools,
1212

1313
Alongside this, React Query Firebase is unopinionated when it comes to integrating with both Firebase and React Query. You can use the library alongside
1414
your existing Firebase or React Query code with zero conflict. You provide the [Query Keys](https://react-query.tanstack.com/guides/query-keys) and a
15-
Firebase instance and the library does the rest. Each hook allows you to also provide React Query hook options, which opens the door to making integration
15+
Firebase instance and the library does the rest. Each hook allows you to also provide React Query hook options, which opens the door to making integration
1616
with the rest of your application super powerful.
1717

1818
Since we've also got access to the awesome [`useMutation`](https://react-query.tanstack.com/reference/useMutation) hook, it means the library provides super useful
@@ -44,5 +44,5 @@ return (
4444
);
4545
```
4646

47-
In this simple example, we've got success and error callback handlers alongside reactive updates within our application, with zero custom local
47+
In this simple example, we've got success and error callback handlers alongside reactive updates within our application, with zero custom local
4848
state management. By integrating with React Query, it allows us to build complex logic flows with minimal effort.

docs/database/querying.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,4 @@ if (query.isError) {
220220
if (query.isSuccess) {
221221
return <ProductList data={query.data} />;
222222
}
223-
```
223+
```

docs/examples/auth-basic.mdx

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ sign-in and sign-out.
1010

1111
> [View example code.](https://github.com/invertase/react-query-firebase/tree/main/examples/auth-basic)
1212
13-
export const iframe = () => <iframe/>;
13+
export const iframe = () => <iframe />;
1414

1515
<iframe
1616
src="https://codesandbox.io/embed/github/invertase/react-query-firebase/tree/main/examples/auth-basic?fontsize=14&hidenavigation=1&theme=dark"
1717
style={{
18-
width: '100%',
19-
height: '700px',
20-
border: '0',
21-
borderRadius: '4px',
22-
overflow: 'hidden',
18+
width: "100%",
19+
height: "700px",
20+
border: "0",
21+
borderRadius: "4px",
22+
overflow: "hidden",
2323
}}
2424
title="invertase/react-query-firebase: auth-basic"
2525
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"

docs/examples/functions-basic.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This example loads a joke from a deployed [callable HTTPS function](https://gith
1010

1111
> [View example code.](https://github.com/invertase/react-query-firebase/tree/main/examples/functions-basic)
1212
13-
export const iframe = () => <iframe/>;
13+
export const iframe = () => <iframe />;
1414

1515
<iframe
1616
src="https://codesandbox.io/embed/github/invertase/react-query-firebase/tree/main/examples/functions-basic?fontsize=14&hidenavigation=1&theme=dark"

docs/firestore/prefetching.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ function Products() {
3737
In the above example, the data for the Query Key is prefetched on the server, and queried on the client.
3838
However, instead of the hook state initially being `loading`, the data will be immidiatley available on the client.
3939

40-
Make sure your server query and client query return the same data model.
40+
Make sure your server query and client query return the same data model.

docs/firestore/querying-documents.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545
import { firestore } from "../firebase";
4646

4747
function Product({ id }) {
48-
const ref = doc(firestore, 'products', id);
48+
const ref = doc(firestore, "products", id);
4949

5050
const product = useFirestoreDocument(["products", id], ref);
5151

docs/firestore/typescript.mdx

+13-13
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ description: TypeScript usage with React Query Firebase.
55

66
# Typescript
77

8-
The library comes with support for a full typesafe API.
8+
The library comes with support for a full typesafe API.
99

1010
## Response types
1111

12-
When fetching a or modifying documents the default return type from
13-
Firestore is a [`QuerySnapshot`](https://firebase.google.com/docs/reference/js/firestore_.querysnapshot) or
12+
When fetching a or modifying documents the default return type from
13+
Firestore is a [`QuerySnapshot`](https://firebase.google.com/docs/reference/js/firestore_.querysnapshot) or
1414
[`DocumentSnapshot`](https://firebase.google.com/docs/reference/js/firestore_.documentsnapshot) whose data type is
1515
[`DocumentData`](https://firebase.google.com/docs/reference/js/firestore_.documentdata).
1616

@@ -36,7 +36,7 @@ useFirestoreDocumentData<Product>(); // Product | null
3636

3737
### Inferred types
3838

39-
The hooks will inferr any types from the provided reference, for example you could
39+
The hooks will inferr any types from the provided reference, for example you could
4040
define [Firestore converters](https://firebase.google.com/docs/reference/js/firestore_.firestoredataconverter):
4141

4242
```ts
@@ -58,28 +58,28 @@ useFirestoreDocumentData('...', docRef); // Product | null
5858

5959
## Data modifications
6060

61-
When returning modified data, you can pass a second type to the hooks for
61+
When returning modified data, you can pass a second type to the hooks for
6262
typesafe result data.
6363

6464
```ts
6565
type Product = {
6666
name: string;
6767
price: number;
68-
}
68+
};
6969

70-
const query = useFirestoreQuery<Product, number | null>('...', ref, undefined, {
70+
const query = useFirestoreQuery<Product, number | null>("...", ref, undefined, {
7171
select(snapshot: QuerySnapshot<Product>): number | null {
7272
if (!snapshot.exists()) {
7373
return null;
7474
}
7575

7676
return snapshot.data().price;
77-
}
77+
},
7878
});
7979

8080
if (query.isSuccess) {
8181
const price = query.data; // number | null
82-
}
82+
}
8383
```
8484

8585
## Mutations
@@ -113,7 +113,7 @@ const mutation = useFirestoreCollectionMutation<Product>(ref);
113113

114114
// mutate expects a Product
115115
mutation.mutate({
116-
name: 'New product',
116+
name: "New product",
117117
price: 10,
118118
});
119119
```
@@ -122,7 +122,7 @@ If working with transactions, you can provide a custom type as the expected
122122
response of the transaction:
123123

124124
```ts
125-
const ref = collection(firebase, 'posts').doc('123');
125+
const ref = collection(firebase, "posts").doc("123");
126126

127127
const mutation = useFirestoreTransaction<number>(firestore, async (tsx) => {
128128
const post = await tsx.get(ref);
@@ -135,6 +135,6 @@ const mutation = useFirestoreTransaction<number>(firestore, async (tsx) => {
135135
});
136136

137137
if (mutation.isSuccess) {
138-
console.log('New likes: ', mutation.data);
138+
console.log("New likes: ", mutation.data);
139139
}
140-
```
140+
```

docs/functions/typescript.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ const mutation = useFunctionsCall<RequestData, ResponseData>(
100100

101101
// mutate call is now typed to RequestData
102102
mutation.mutate({
103-
id: '...',
104-
name: '...',
103+
id: "...",
104+
name: "...",
105105
});
106106

107107
if (mutation.isSuccess) {

examples/auth-basic/public/index.html

+19-20
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
4-
<head>
5-
<meta charset="utf-8">
6-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7-
<meta name="theme-color" content="#000000">
8-
<!--
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta
6+
name="viewport"
7+
content="width=device-width, initial-scale=1, shrink-to-fit=no"
8+
/>
9+
<meta name="theme-color" content="#000000" />
10+
<!--
911
manifest.json provides metadata used when your web app is added to the
1012
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
1113
-->
12-
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
13-
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
14-
<!--
14+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
15+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
16+
<!--
1517
Notice the use of %PUBLIC_URL% in the tags above.
1618
It will be replaced with the URL of the `public` folder during the build.
1719
Only files inside the `public` folder can be referenced from the HTML.
@@ -20,15 +22,13 @@
2022
work correctly both with client-side routing and a non-root public URL.
2123
Learn how to configure a non-root public URL by running `npm run build`.
2224
-->
23-
<title>React App</title>
24-
</head>
25+
<title>React App</title>
26+
</head>
2527

26-
<body>
27-
<noscript>
28-
You need to enable JavaScript to run this app.
29-
</noscript>
30-
<div id="root"></div>
31-
<!--
28+
<body>
29+
<noscript> You need to enable JavaScript to run this app. </noscript>
30+
<div id="root"></div>
31+
<!--
3232
This HTML file is a template.
3333
If you open it directly in the browser, you will see an empty page.
3434
@@ -38,6 +38,5 @@
3838
To begin the development, run `npm start` or `yarn start`.
3939
To create a production bundle, use `npm run build` or `yarn build`.
4040
-->
41-
</body>
42-
43-
</html>
41+
</body>
42+
</html>

0 commit comments

Comments
 (0)