Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
componentDidMount = async () => {
await Auth.currentAuthenticatedUser()
.then(user => {
this.setState(
{
postOwnerUsername: user.username,
likeOwnerUsername: user.username,
postOwnerId: user.attributes.sub,
likeOwnerId: user.attributes.sub,
}
)
})
.catch(err => console.log(err))
await this.listPosts()
// Update the number of entries in the parent component: ChallengeScreen
await this.props.countPosts()
}
async function getUser() {
if (!user) {
console.log("Getting current authenticated user");
user = await Auth.currentAuthenticatedUser();
}
return user;
}
).then((cred) => {
if (onStateChange) {
Auth.currentAuthenticatedUser().then(user => {
onStateChange('signedIn', user);
});
}
}).catch((e) => {
logger.debug('Failed to get the aws credentials', e);
checkUser() {
if (!Auth || typeof Auth.currentAuthenticatedUser !== 'function') {
throw new Error(
'No Auth module found, please ensure @aws-amplify/auth is imported'
);
}
return Auth.currentAuthenticatedUser()
.then(user => {
if (!this._isMounted) {
return;
}
this.handleStateChange('signedIn', user);
})
.catch(err => {
if (!this._isMounted) {
return;
}
let cachedAuthState = null;
try {
cachedAuthState = localStorage.getItem(AUTHENTICATOR_AUTHSTATE);
} catch (e) {
logger.debug('Failed to get the auth state from local storage', e);
}
findState() {
if (!this.props.authState && !this.props.authData) {
Auth.currentAuthenticatedUser()
.then(user => {
this.setState({
authState: 'signedIn',
authData: user,
stateFromStorage: true,
});
})
.catch(err => logger.debug(err));
}
}
!Auth ||
typeof Auth.federatedSignIn !== 'function' ||
typeof Auth.currentAuthenticatedUser !== 'function'
) {
throw new Error(
'No Auth module found, please ensure @aws-amplify/auth is imported'
);
}
await Auth.federatedSignIn(
'google',
{ token: id_token, expires_at },
user
);
user = await Auth.currentAuthenticatedUser();
if (onStateChange) {
onStateChange('signedIn', user);
}
}
findState(){
if (!this.props.authState && !this.props.authData) {
Auth.currentAuthenticatedUser()
.then(user => {
this.setState({
authState: 'signedIn',
authData: user,
stateFromStorage: true
})
})
.catch(err => logger.error(err));
} else if (this.props.stateFromStorage) {
this.setState({
stateFromStorage: true
})
}
}