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

Use ReactNativeAsyncStorage from community package. #7128

Merged
merged 4 commits into from
Jul 5, 2023
Merged
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
6 changes: 6 additions & 0 deletions .changeset/two-bags-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@firebase/auth': major
'firebase': major
---

Change `getAuth()` in the React Native bundle to default to importing `AsyncStorage` from `@react-native-async-storage/async-storage` instead of from the `react-native` core package (which has recently removed it).
11 changes: 0 additions & 11 deletions docs-devsite/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ Firebase Authentication
| [OperationType](./auth.md#operationtype) | Enumeration of supported operation types. |
| [prodErrorMap](./auth.md#proderrormap) | A minimal error map with all verbose error messages stripped.<!-- -->See discussion at [AuthErrorMap](./auth.autherrormap.md#autherrormap_interface) |
| [ProviderId](./auth.md#providerid) | Enumeration of supported providers. |
| [reactNativeLocalPersistence](./auth.md#reactnativelocalpersistence) | An implementation of [Persistence](./auth.persistence.md#persistence_interface) of type 'LOCAL' for use in React Native environments. |
| [SignInMethod](./auth.md#signinmethod) | Enumeration of supported sign-in methods. |

## Type Aliases
Expand Down Expand Up @@ -1969,16 +1968,6 @@ ProviderId: {
}
```

## reactNativeLocalPersistence

An implementation of [Persistence](./auth.persistence.md#persistence_interface) of type 'LOCAL' for use in React Native environments.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why this was exposed externally. Looks like the index.rn.ts was using "reactNativeLocalPersistence" as part of getAuth, but the developer wasn;t directly passing it as a param to initializeAuth, were they?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't actually remember the reason, maybe in case the users wanted to call it explicitly, or if they wanted to add multiple persistences (use the array format) for some reason, although I can't think of another persistence you'd want to add for React Native.


<b>Signature:</b>

```typescript
reactNativeLocalPersistence: Persistence
```

## SignInMethod

Enumeration of supported sign-in methods.
Expand Down
5 changes: 1 addition & 4 deletions packages/auth/index.doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,4 @@
export * from './index';

export { cordovaPopupRedirectResolver } from './index.cordova';
export {
reactNativeLocalPersistence,
getReactNativePersistence
} from './index.rn';
export { getReactNativePersistence } from './index.rn';
29 changes: 3 additions & 26 deletions packages/auth/index.rn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
* just use index.ts
*/

import * as ReactNative from 'react-native';

import { FirebaseApp, getApp, _getProvider } from '@firebase/app';
import { Auth, Persistence } from './src/model/public_types';
import { Auth } from './src/model/public_types';

import { initializeAuth } from './src';
import { registerAuth } from './src/core/auth/register';
import { ClientPlatform } from './src/core/util/version';
import { getReactNativePersistence } from './src/platform_react_native/persistence/react_native';
import ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';

// Core functionality shared by all clients
export * from './index.shared';
Expand All @@ -50,28 +49,6 @@ export {
// MFA
export { PhoneMultiFactorGenerator } from './src/platform_browser/mfa/assertions/phone';

/**
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reviewers: This section was added as a hack to import from react-native core by default (which will normally show a warning), but not show the warning if the user overrides the default and provides the newer community version of AsyncStorage. Since this change makes the community package the default, this isn't needed anymore.

* An implementation of {@link Persistence} of type 'LOCAL' for use in React
* Native environments.
*
* @public
*/
export const reactNativeLocalPersistence: Persistence =
getReactNativePersistence({
getItem(...args) {
// Called inline to avoid deprecation warnings on startup.
return ReactNative.AsyncStorage.getItem(...args);
},
setItem(...args) {
// Called inline to avoid deprecation warnings on startup.
return ReactNative.AsyncStorage.setItem(...args);
},
removeItem(...args) {
// Called inline to avoid deprecation warnings on startup.
return ReactNative.AsyncStorage.removeItem(...args);
}
});

export { getReactNativePersistence };

export function getAuth(app: FirebaseApp = getApp()): Auth {
Expand All @@ -82,7 +59,7 @@ export function getAuth(app: FirebaseApp = getApp()): Auth {
}

return initializeAuth(app, {
persistence: reactNativeLocalPersistence
persistence: getReactNativePersistence(ReactNativeAsyncStorage)
});
}

Expand Down
2 changes: 2 additions & 0 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"@firebase/component": "0.6.4",
"@firebase/logger": "0.4.0",
"@firebase/util": "1.9.3",
"@react-native-async-storage/async-storage": "1.17.12",
"node-fetch": "2.6.7",
"tslib": "^2.1.0"
},
Expand All @@ -122,6 +123,7 @@
"@firebase/app": "0.9.10",
"@rollup/plugin-json": "4.1.0",
"@rollup/plugin-strip": "2.1.0",
"@types/express": "4.17.17",
"chromedriver": "98.0.1",
"rollup": "2.79.1",
"rollup-plugin-sourcemaps": "0.6.3",
Expand Down
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3050,6 +3050,13 @@
resolved "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=

"@react-native-async-storage/[email protected]":
version "1.17.12"
resolved "https://registry.npmjs.org/@react-native-async-storage/async-storage/-/async-storage-1.17.12.tgz#a39e4df5b06795ce49b2ca5b7ca9b8faadf8e621"
integrity sha512-BXg4OxFdjPTRt+8MvN6jz4muq0/2zII3s7HeT/11e4Zeh3WCgk/BleLzUcDfVqF3OzFHUqEkSrb76d6Ndjd/Nw==
dependencies:
merge-options "^3.0.4"

"@rollup/[email protected]":
version "3.1.9"
resolved "https://registry.npmjs.org/@rollup/plugin-alias/-/plugin-alias-3.1.9.tgz#a5d267548fe48441f34be8323fb64d1d4a1b3fdf"
Expand Down Expand Up @@ -12251,6 +12258,13 @@ [email protected]:
resolved "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61"
integrity sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=

merge-options@^3.0.4:
version "3.0.4"
resolved "https://registry.npmjs.org/merge-options/-/merge-options-3.0.4.tgz#84709c2aa2a4b24c1981f66c179fe5565cc6dbb7"
integrity sha512-2Sug1+knBjkaMsMgf1ctR1Ujx+Ayku4EdJN4Z+C2+JzoeF7A3OZ9KM2GY0CpQS51NR61LTurMJrRKPhSs3ZRTQ==
dependencies:
is-plain-obj "^2.1.0"

merge-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
Expand Down