aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.4k stars 2.11k forks source link

using MMKV storage instead of Async-storage doesn't work in android #8968

Open valin0k opened 2 years ago

valin0k commented 2 years ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Storage

Amplify Categories

auth

Environment information

``` # Put output below this line System: OS: macOS 11.4 CPU: (12) x64 AMD Ryzen 5 3600 6-Core Processor Memory: 2.81 GB / 32.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 16.2.0 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 7.19.1 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Browsers: Chrome Canary: 96.0.4656.3 npmPackages: @aws-amplify/analytics: ^5.0.18 => 5.0.18 @aws-amplify/pushnotification: ^4.2.12 => 4.2.12 @babel/cli: ^7.15.7 => 7.15.7 @babel/core: ^7.15.5 => 7.15.5 @babel/plugin-proposal-class-properties: ^7.14.5 => 7.14.5 @babel/plugin-proposal-decorators: ^7.15.4 => 7.15.4 @babel/plugin-proposal-export-namespace-from: ^7.14.5 => 7.14.5 @babel/plugin-proposal-object-rest-spread: ^7.15.6 => 7.15.6 @babel/preset-typescript: ^7.15.0 => 7.15.0 @babel/runtime: ^7.15.4 => 7.15.4 @bugsnag/react-native: ^7.13.1 => 7.13.1 @bugsnag/source-maps: ^2.3.0 => 2.3.0 @dudigital/react-native-zoomable-view: ^1.1.3 => 1.1.3 @emotion/babel-plugin: ^11.3.0 => 11.3.0 @emotion/native: ^11.0.0 => 11.0.0 @emotion/react: ^11.4.1 => 11.4.1 @jonni/pdf: 1.0.5 => 1.0.5 @react-native-async-storage/async-storage: ^1.15.8 => 1.15.8 @react-native-clipboard/clipboard: ^1.8.4 => 1.8.4 @react-native-community/datetimepicker: ^3.5.2 => 3.5.2 @react-native-community/eslint-config: ^3.0.1 => 3.0.1 @react-native-community/eslint-plugin: ^1.1.0 => 1.1.0 @react-native-community/netinfo: ^6.0.2 => 6.0.2 @react-native-community/progress-bar-android: ^1.0.4 => 1.0.4 @react-native-community/progress-view: ^1.3.1 => 1.3.1 @react-native-community/push-notification-ios: ^1.10.1 => 1.10.1 (1.0.3) @react-native-picker/picker: ^2.1.0 => 2.1.0 (1.16.8) @sharcoux/slider: ^5.5.2 => 5.5.2 @types/gravatar: ^1.8.3 => 1.8.3 @types/jest: ^27.0.2 => 27.0.2 @types/lodash.clonedeep: ^4.5.6 => 4.5.6 @types/node: ^16.10.1 => 16.10.1 @types/numeral: ^2.0.2 => 2.0.2 @types/react: ^17.0.24 => 17.0.24 @types/react-native: ^0.65.1 => 0.65.1 @types/react-native-material-textfield: ^0.16.5 => 0.16.5 @types/react-native-signature-capture: ^0.4.2 => 0.4.2 @types/react-native-snap-carousel: ^3.8.4 => 3.8.4 @types/react-native-svg-charts: ^5.0.9 => 5.0.9 @types/react-redux: ^7.1.18 => 7.1.18 @types/react-test-renderer: ^17.0.1 => 17.0.1 @types/uuid: ^8.3.1 => 8.3.1 @types/yup: ^0.29.13 => 0.29.13 @typescript-eslint/eslint-plugin: ^4.31.2 => 4.31.2 @typescript-eslint/parser: ^4.31.2 => 4.31.2 HelloWorld: 0.0.1 PDFExample: 0.0.1 SignatureCaptureExample: 0.0.1 amazon-cognito-identity-js: ^5.1.2 => 5.1.2 aws-amplify: ^4.3.0 => 4.3.0 babel-jest: ^27.2.2 => 27.2.2 babel-plugin-module-resolver: ^4.1.0 => 4.1.0 babel-plugin-transform-remove-console: ^6.9.4 => 6.9.4 buffer: ^6.0.3 => 6.0.3 (4.9.2) debounce: ^1.2.1 => 1.2.1 detox: ^18.21.0 => 18.21.0 eslint: ^7.32.0 => 7.32.0 eslint-config-prettier: ^8.3.0 => 8.3.0 (6.15.0) eslint-plugin-jest: ^24.4.2 => 24.4.2 (22.4.1) eslint-plugin-json: ^3.1.0 => 3.1.0 eslint-plugin-prettier: ^4.0.0 => 4.0.0 (3.1.2) formik: ^2.2.9 => 2.2.9 gravatar: ^1.8.2 => 1.8.2 hermes-inspector-msggen: 1.0.0 husky: ^7.0.2 => 7.0.2 i18next: ^21.1.1 => 21.1.1 jest: ^27.2.2 => 27.2.2 jest-circus: ^27.2.2 => 27.2.2 lint-staged: ^11.1.2 => 11.1.2 lodash.clonedeep: ^4.5.0 => 4.5.0 metro-react-native-babel-preset: ^0.66.2 => 0.66.2 moment: ^2.29.1 => 2.29.1 numbro: ^2.3.5 => 2.3.5 patch-package: ^6.4.7 => 6.4.7 postinstall-postinstall: ^2.1.0 => 2.1.0 prettier: ^2.4.1 => 2.4.1 prop-types: ^15.7.2 => 15.7.2 react: ^17.0.2 => 17.0.2 react-i18next: 11.12.0 => 11.12.0 react-native: ^0.65.1 => 0.65.1 react-native-auto-height-image: ^3.2.4 => 3.2.4 react-native-camera: ^4.2.1 => 4.2.1 react-native-clean-project: ^3.6.7 => 3.6.7 react-native-codegen: ^0.0.8 => 0.0.8 react-native-confetti-cannon: ^1.5.2 => 1.5.2 react-native-dash: ^0.0.11 => 0.0.11 react-native-device-info: ^8.3.3 => 8.3.3 react-native-file-viewer: ^2.1.4 => 2.1.4 react-native-fs: ^2.18.0 => 2.18.0 react-native-geolocation-service: ^5.3.0-beta.3 => 5.3.0-beta.3 react-native-gesture-handler: ^1.10.3 => 1.10.3 react-native-get-random-values: ^1.7.0 => 1.7.0 react-native-google-places-autocomplete: ^2.4.1 => 2.4.1 react-native-haptic-feedback: ^1.11.0 => 1.11.0 react-native-image-picker: ^4.1.1 => 4.1.1 react-native-localize: ^2.1.4 => 2.1.4 react-native-mask-input: ^1.0.3 => 1.0.3 react-native-material-textfield: ^0.16.1 => 0.16.1 react-native-mmkv: ^1.3.2 => 1.3.2 react-native-mmkv-storage: ^0.6.4 => 0.6.4 react-native-modal-datetime-picker: ^11.0.0 => 11.0.0 react-native-modalize: ^2.0.8 => 2.0.8 react-native-navigation: ^7.21.0 => 7.21.0 react-native-pdf: ^6.3.0 => 6.3.0 react-native-permissions: ^3.0.5 => 3.0.5 react-native-picker-select: ^8.0.4 => 8.0.4 react-native-reanimated: ^2.2.2 => 2.2.2 react-native-share: ^7.1.1 => 7.1.1 react-native-share-menu: ^5.0.4 => 5.0.4 react-native-signature-capture: ^0.4.12 => 0.4.12 react-native-snap-carousel: ^4.0.0-beta.6 => 4.0.0-beta.6 react-native-svg: ^12.1.1 => 12.1.1 (6.5.3) react-native-typescript-transformer: ^1.2.13 => 1.2.13 react-native-ultimate-config: ^3.4.1 => 3.4.1 react-native-webview: ^11.13.1 => 11.13.1 react-query: ^3.24.4 => 3.24.4 react-redux: ^7.2.5 => 7.2.5 react-test-renderer: ^17.0.2 => 17.0.2 reactotron-react-native: ^5.0.0 => 5.0.0 reactotron-redux: ^3.1.3 => 3.1.3 redux: ^4.1.1 => 4.1.1 redux-persist: ^6.0.0 => 6.0.0 redux-persist/integration/react: undefined () redux-saga: ^1.1.3 => 1.1.3 redux-saga/effects: undefined () rn-async-storage-flipper: ^0.0.10 => 0.0.10 rn-fetch-blob: ^0.12.0 => 0.12.0 twitter_cldr: ^2.2.0 => 2.2.0 typescript: ^4.4.3 => 4.4.3 uuid: ^8.3.2 => 8.3.2 (3.4.0, 3.3.2) yup: ^0.32.9 => 0.32.9 npmGlobalPackages: detox-cli: 18.20.1 expo-cli: 4.7.3 node-gyp: 8.1.0 npm: 7.19.1 react-native: 0.64.2 react: 17.0.1 ```

Describe the bug

I used async-storage implementation from here https://docs.amplify.aws/lib/auth/manageusers/q/platform/js/#managing-security-tokens and with async-storage it working on both iOS and Android, but when i changed implementation to MMKV package - https://github.com/ammarahm-ed/react-native-mmkv-storage , authorization only work on iOS, but not on Android. Also i printed key/value inside the getItem method: key: CognitoIdentityServiceProvider.securityKey.+0101014557.deviceKey, value: undefined

Снимок экрана 2021-09-30 в 13 28 44

Expected behavior

i expect that signin will work correctly as for iOS

Reproduction steps

inside the Amplify config file:

import Amplify, { Auth } from 'aws-amplify';

const config = {
  ...config,
  Auth: {
    storage: AmplifyMmkvStorage,
  },
};
Amplify.configure(config);

and the storage file:

import MMKVStorage from 'react-native-mmkv-storage';
const MMKV = new MMKVStorage.Loader().initialize();

interface MMKVStorage extends Storage {
  multiRemove(keys: Array<string>): any;
  getAllKeys(): any;
  multiGet(keys: Array<string>): any;
}

export const storage: MMKVStorage = {
  setItem: (key: string, value: string) => {
    MMKV.setString(key, value);
    return Promise.resolve(true);
  },
  getItem: key => {
    return Promise.resolve(MMKV.getString(key));
  },
  removeItem: key => {
    MMKV.removeItem(key);
    return Promise.resolve(true);
  },
  multiRemove: (keys: Array<string>): Promise<any> => {
    const promises = keys.map(key => MMKV.removeItem(key));
    return createPromiseAll(promises);
  },
  getAllKeys: async (): Promise<any> => {
    const stringKeys = await MMKV.indexer.strings.getKeys();
    return Promise.resolve(stringKeys);
  },
  multiGet: (keys): Promise<any> => {
    const entities = keys.map(key => [key, MMKV.getString(key)]);
    return Promise.resolve(entities);
  },
};

And after that import it as AsyncStorage inside the MyStorage example

Code Snippet

// Put your code below this line.
described inside the Reproduction steps

Log output

``` // Put your logs below this line '[ERROR] 27:05.46 AuthClass - Failed to get the signed in user', [TypeError: Cannot read property 'filter' of undefined] ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

android 9

Mobile Operating System

api 28

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

sammartinez commented 2 years ago

Thanks for reaching out on this, I have converted this issue to a feature request as we do not currently support MMKV as a Storage option for React Native. Please upvote this feature request if you are looking for this. Thanks!