Skip to content

Commit 8d3c2c5

Browse files
committed
Merge branch 'pasta/main' into pasta/ziti
2 parents 27067f8 + 11aa0c7 commit 8d3c2c5

5 files changed

Lines changed: 64 additions & 5 deletions

File tree

.changeset/funky-teeth-pick.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'firebase': minor
3+
'@firebase/auth': minor
4+
---
5+
6+
Updated the peer dependency range for @react-native-async-storage/async-storage to support both v2 and v3

docs-devsite/auth.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Firebase Authentication
2020
| [getAuth(app)](./auth.md#getauth_cf608e1) | Returns the Auth instance associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface)<!-- -->. If no instance exists, initializes an Auth instance with platform-specific default dependencies. |
2121
| [initializeAuth(app, deps)](./auth.md#initializeauth_ca77c9b) | Initializes an [Auth](./auth.auth.md#auth_interface) instance with fine-grained control over [Dependencies](./auth.dependencies.md#dependencies_interface)<!-- -->. |
2222
| <b>function(storage, ...)</b> |
23-
| [getReactNativePersistence(storage)](./auth.md#getreactnativepersistence_bab4ada) | Returns a persistence object that wraps <code>AsyncStorage</code> imported from <code>react-native</code> or <code>@react-native-community/async-storage</code>, and can be used in the persistence dependency field in [initializeAuth()](./auth.md#initializeauth_ca77c9b)<!-- -->. |
23+
| [getReactNativePersistence(storage)](./auth.md#getreactnativepersistence_bab4ada) | Returns a persistence object that wraps <code>AsyncStorage</code> imported from <code>react-native</code> or <code>@react-native-async-storage/async-storage</code>, and can be used in the persistence dependency field in [initializeAuth()](./auth.md#initializeauth_ca77c9b)<!-- -->. |
2424
| <b>function(auth, ...)</b> |
2525
| [applyActionCode(auth, oobCode)](./auth.md#applyactioncode_d2ae15a) | Applies a verification code sent to the user by email or other out-of-band mechanism. |
2626
| [beforeAuthStateChanged(auth, callback, onAbort)](./auth.md#beforeauthstatechanged_22f2ab6) | Adds a blocking callback that runs before an auth state change sets a new user. |
@@ -232,7 +232,7 @@ export declare function initializeAuth(app: FirebaseApp, deps?: Dependencies): A
232232

233233
### getReactNativePersistence(storage) {:#getreactnativepersistence_bab4ada}
234234

235-
Returns a persistence object that wraps `AsyncStorage` imported from `react-native` or `@react-native-community/async-storage`<!-- -->, and can be used in the persistence dependency field in [initializeAuth()](./auth.md#initializeauth_ca77c9b)<!-- -->.
235+
Returns a persistence object that wraps `AsyncStorage` imported from `react-native` or `@react-native-async-storage/async-storage`<!-- -->, and can be used in the persistence dependency field in [initializeAuth()](./auth.md#initializeauth_ca77c9b)<!-- -->.
236236

237237
<b>Signature:</b>
238238

@@ -250,6 +250,28 @@ export declare function getReactNativePersistence(storage: ReactNativeAsyncStora
250250

251251
[Persistence](./auth.persistence.md#persistence_interface)
252252

253+
### Example
254+
255+
256+
```javascript
257+
import { initializeAuth, getReactNativePersistence } from 'firebase/auth';
258+
259+
// For @react-native-async-storage/async-storage v3:
260+
import { createAsyncStorage } from '@react-native-async-storage/async-storage';
261+
const appStorage = createAsyncStorage('app');
262+
const persistence = getReactNativePersistence(appStorage);
263+
264+
// For @react-native-async-storage/async-storage v2:
265+
// import ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';
266+
// const persistence = getReactNativePersistence(ReactNativeAsyncStorage);
267+
268+
// Then, initialize auth:
269+
const auth = initializeAuth(app, {
270+
persistence
271+
});
272+
273+
```
274+
253275
## function(auth, ...)
254276

255277
### applyActionCode(auth, oobCode) {:#applyactioncode_d2ae15a}

packages/auth/index.rn.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,21 @@ persist between sessions. In order to persist auth state, install the package
6262
initializeAuth:
6363
6464
import { initializeAuth, getReactNativePersistence } from 'firebase/auth';
65+
66+
// For @react-native-async-storage/async-storage v3:
67+
import { createAsyncStorage } from '@react-native-async-storage/async-storage';
68+
const appStorage = createAsyncStorage("app");
69+
const persistence = getReactNativePersistence(appStorage);
70+
71+
/*
72+
// For @react-native-async-storage/async-storage v2:
6573
import ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';
74+
const persistence = getReactNativePersistence(ReactNativeAsyncStorage);
75+
*/
76+
77+
// Then, initialize auth:
6678
const auth = initializeAuth(app, {
67-
persistence: getReactNativePersistence(ReactNativeAsyncStorage)
79+
persistence
6880
});
6981
`;
7082

packages/auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
},
117117
"peerDependencies": {
118118
"@firebase/app": "0.x",
119-
"@react-native-async-storage/async-storage": "^2.2.0"
119+
"@react-native-async-storage/async-storage": "^2.2.0 || ^3.0.0"
120120
},
121121
"peerDependenciesMeta": {
122122
"@react-native-async-storage/async-storage": {

packages/auth/src/platform_react_native/persistence/react_native.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,28 @@ import {
2727

2828
/**
2929
* Returns a persistence object that wraps `AsyncStorage` imported from
30-
* `react-native` or `@react-native-community/async-storage`, and can
30+
* `react-native` or `@react-native-async-storage/async-storage`, and can
3131
* be used in the persistence dependency field in {@link initializeAuth}.
3232
*
33+
* @example
34+
* ```javascript
35+
* import { initializeAuth, getReactNativePersistence } from 'firebase/auth';
36+
*
37+
* // For @react-native-async-storage/async-storage v3:
38+
* import { createAsyncStorage } from '@react-native-async-storage/async-storage';
39+
* const appStorage = createAsyncStorage('app');
40+
* const persistence = getReactNativePersistence(appStorage);
41+
*
42+
* // For @react-native-async-storage/async-storage v2:
43+
* // import ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';
44+
* // const persistence = getReactNativePersistence(ReactNativeAsyncStorage);
45+
*
46+
* // Then, initialize auth:
47+
* const auth = initializeAuth(app, {
48+
* persistence
49+
* });
50+
* ```
51+
*
3352
* @public
3453
*/
3554
export function getReactNativePersistence(

0 commit comments

Comments
 (0)