Реагируй на натив, усиливай AWS-усиление, получая aws.cognito.identity-id - PullRequest
2 голосов
/ 13 марта 2019

Я пытаюсь получить aws.cognito.identity-id с помощью React-Native.После успешного входа я получаю CognitoUser, но переменная хранения равна [Function MemoryStorage], однако с React в моем хранилище веб-браузера есть некоторые значения.Код в React и React native точно такой же.

Вывод браузера:

...
    storage: Storage
    CognitoIdentityId-eu-central-1:...: "..."
    CognitoIdentityServiceProvider.....LastAuthUser: "..."
    CognitoIdentityServiceProvider.........accessToken: "..."
    CognitoIdentityServiceProvider........clockDrift: "2"
...

Вывод устройства Android:

...
 "storage": [Function MemoryStorage],
...

Код

Amplify.configure({
     ...awsmobile
});

const client = new AWSAppSyncClient({
     url: awsmobile.aws_appsync_graphqlEndpoint,
     region: awsmobile.aws_appsync_region,
     auth: {
          type: AUTH_TYPE.AWS_IAM,
          credentials: () => Auth.currentCredentials()
     },
});

Auth.signIn(
     'myemail@gmail.com',
     'pass'
)
// .then(user => console.log('user',user))
     .then(user => signInSuccess(user));

function getValueFromKey(myObject, string) {
     const key = Object.keys(myObject).filter(k => k.includes(string));
     return key.length ? myObject[key] : "";
}

function signInSuccess(user) {
     console.log('another', user);
     console.log(getValueFromKey(user.storage, 'aws.cognito.identity-id'))
}

export default class App extends React.Component {
     render() {
          return (
               <Text>nice</Text>
          );
     }
}
...