_Do you want to request a feature or report a bug_
Not sure if it is a bug, or I am doing something wrong
_What is the current behavior?_
1) Auth.currentUserInfo()
returns the user information after the user signs in.
javascript
{
attributes: { ... } // ok
id: undefined // btw, why is this undefined?
username: "johndoe" // ok
}
2) If you reload the app, the user is still signed in (as determined by checkUser
in Authenticator
) but now Auth.currentUserInfo()
returns an empty object.
javascript
{}
Logged error:
YellowBox.js:82 TypeError: Cannot read property 'identityId' of null
at AuthClass.<anonymous> (Auth.js:781)
at step (Auth.js:44)
at Object.next (Auth.js:25)
at fulfilled (Auth.js:16)
at tryCallOne (core.js:37)
at core.js:123
at JSTimers.js:301
at _callTimer (JSTimers.js:154)
at _callImmediatesPass (JSTimers.js:202)
at Object.callImmediates (JSTimers.js:470)
_What is the expected behavior?_
I think it should return the user information in both cases.
_Code for reproducing the issue_
````javascript
import React from 'react';
import Amplify, { Auth } from 'aws-amplify';
import { withAuthenticator } from 'aws-amplify-react-native';
import { StyleSheet, Text, View, Button } from 'react-native';
Amplify.configure({
Auth: {
identityPoolId: '',
region: 'us-east-1',
userPoolId: '',
userPoolWebClientId: '',
}
})
class App extends React.Component {
state = {
info: {}
}
signOut = async () => {
await Auth.signOut()
this.setState({info: {}})
this.props.onStateChange('signedOut')
}
async componentDidMount() {
const info = await Auth.currentUserInfo()
console.log('Returned info: ', info)
this.setState({ info })
}
render() {
const { info } = this.state
const { username } = info
return (
title="Sign Out"
onPress={this.signOut}
/>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
export default withAuthenticator(App)
````
Hi @ldgarcia
I was able to replicate the behavior you are seeing, this is a bug in the library.
I was able to identify a workaround for you while we work on a bugfix:
Change your componentDidMount
like this:
async componentDidMount() {
await (await Auth.currentCredentials()).getPromise(); // Wait for credentials
const info = await Auth.currentUserInfo()
console.log('Returned info: ', info)
this.setState({ info })
}
For context, the library tries to read the identityId from the credentials, those might not be ready yet when calling Auth.currentUserInfo()
Thanks @manueliglesias, I will try using the workaround.
Issue fixed in #331
Most helpful comment
Hi @ldgarcia
I was able to replicate the behavior you are seeing, this is a bug in the library.
I was able to identify a workaround for you while we work on a bugfix:
Change your
componentDidMount
like this:For context, the library tries to read the identityId from the credentials, those might not be ready yet when calling
Auth.currentUserInfo()