Closed llhyatt98 closed 1 year ago
Hi @llhyatt98 👋 thanks for raising this issue. A few questions:
withAuthenticator
UI component?Hi @chrisbonifacio - thanks for getting back on this. In response to each point:
@llhyatt98 Does the MFA you set up (SMS/TOTP) get triggered when you try this flow? Can you try the Amplify Logger on an app/component level to see what is shown when logging in? I realize you said there are no errors while logging in but I want to make sure there is success also
Amplify.Logger.LOG_LEVEL = 'DEBUG';
@llhyatt98 In regards to the 1st question @chrisbonifacio had asked, Amplify Auth automatically stores in AsyncStorage for React Native projects so you would need to look there.
I also noticed something small with this one that may or may not be your issue
Auth.currentAuthenticatedUser(() => console.log(user))
This (and all of the ones you mentioned) are async functions and can't be used like this to retrieve the credentials It would instead need to be used like the following
Auth.currentAuthenticatedUser()
.then(user => console.log(user))
.catch(err => console.log(err))
Hi 👋 Closing this as we have not heard back from you. If you are still experiencing this issue and are in need of assistance, please feel free to comment and provide us with any information previously requested by our team members so we can re-open this issue and be better able to assist you.
Thank you!
Describe the bug I'm facing this issue on ios. I'm not getting any response while calling the currentAuthenticatedUser. I'm calling this function just as you shown. It works on android.
package.json
"aws-amplify": "^4.3.29", "react": "17.0.2", "react-native": "0.66.4"
aws-exports.js
const awsmobile = {
"aws_project_region": "us-east-2",
"aws_cognito_identity_pool_id": "us-east-2:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"aws_cognito_region": "us-east-2",
"aws_user_pools_id": "us-east-2_xxxxxxxxx",
"aws_user_pools_web_client_id": "31gs1iqkbeffj006j69odt5ns6",
"oauth": {
"domain": "myapp98xxxxxx-98xxxxxx-dev.auth.us-east-2.amazoncognito.com",
"scope": [
"phone",
"email",
"openid",
"profile",
"aws.cognito.signin.user.admin"
],
"redirectSignIn": "myapp://",
"redirectSignOut": "myapp://",
"responseType": "code"
},
"federationTarget": "COGNITO_USER_POOLS",
"aws_cognito_username_attributes": [
"EMAIL",
"PHONE_NUMBER"
],
"aws_cognito_social_providers": [
"FACEBOOK",
"GOOGLE",
"APPLE"
],
"aws_cognito_signup_attributes": [
"EMAIL"
],
"aws_cognito_mfa_configuration": "OFF",
"aws_cognito_mfa_types": [
"SMS"
],
"aws_cognito_password_protection_settings": {
"passwordPolicyMinLength": 8,
"passwordPolicyCharacters": []
},
"aws_cognito_verification_mechanisms": [
"EMAIL"
]
};
export default awsmobile;
Hi @Haider-Ali-7, would you mind giving a short code snippet of how you are using it and where
I have used currentAuthenticatedUser function inside useEffect with or without side-effects. It didn't work.
import {Amplify, Auth, Hub} from 'aws-amplify';
import config from '../aws-exports';
import InAppBrowser from 'react-native-inappbrowser-reborn'
const urlOpener = async (url, redirectUrl) => {
InAppBrowser.openAuth(url, redirectUrl, {
dismissButtonStyle: 'cancel',
showTitle: false,
enableUrlBarHiding: true,
enableDefaultShare: false,
ephemeralWebSession: false,
}).then((res) => {
if (res === 'SUCCESS') {
Linking.openURL(res.url);
}
}).catch(err => console.log("urlOpener err: ", err))
}
Amplify.configure({
...config,
oauth: {
...config.oauth,
urlOpener
}
});
const Login = props => {
useEffect(() => {
const unsubscribe = Hub.listen('auth', ({payload: {event, data}}) => {
switch (event) {
case 'signIn':
console.log('signIn', data);
break;
case 'signOut':
console.log('sign out!');
break;
default:
console.log("default User", data);
break;
}
});
return unsubscribe;
}, []);
Auth.currentAuthenticatedUser()
.then(user => console.log("currentAuthenticatedUser", user))
.catch((err) => console.log('currentAuthenticatedUser err: ', err));
}
export default Login;
@Haider-Ali-7 are your events firing and signin working when you login?
Also are you just running the function by itself inside of your component?
Because right now we are configuring Identity provider pool Username attribute to have value other than id. I do get user details in pool if signIn on android device. SignIn doesn't fire on ios.
For function I have tested three ways:
const Login = props => {
useEffect(() => {
const unsubscribe = Hub.listen('auth', ({payload: {event, data}}) => {
switch (event) {
case 'signIn':
console.log('signIn', data);
break;
case 'signOut':
console.log('sign out!');
break;
default:
console.log("default User", data);
break;
}
});
// called here currentAuthenticatedUser() ---didn't work
return unsubscribe;
}, []); //with sideeffects ---didn't work
//right now calling currentAuthenticatedUser() here ---didn't work
}
export default Login;
Did you set up the Linking
module in AppDelegate.m
for this project? See docs on it here in the first note
Also is that line if (res === 'SUCCESS') {
working properly? It's written different from the docs and I see what is trying to be done but I think if you go about it that way you would need to do if (res.type === 'success') {
1 - Already Configured Linking
2 - if (res.type === 'success') { //Sorry I wrote the code wrong here.
It's not a solution. But more of a cleansing the project. It worked for me. Here what I did
yarn cache clean
pod cache clean
podfile.lock //deleted
pod install
Start the project. Now i'm getting the user details in ios too.🎉 You can close the issue. Thanks you for helping out.
Thank you @Haider-Ali-7 for detailing your solution in case anyone else finds this issue. If you have any other issues with Amplify, please feel free to open a new issue or join our discord channel for help from the community.
Thank you!
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
Authentication
Amplify Categories
auth
Environment information
Describe the bug
We are integrating with amplify authentication in our react native app (runs on expo). We can authenticated a user to sign up or log in at any time, but after logging in we cannot get current user data while they are in the app. The session data does not seem to be saving, there are related issues on this topic but none of which seem to have been closed.
Expected behavior
According to the docs, we should be able to access current user data once they have logged in through the Auth module.
Reproduction steps
This bug is triggered when we make a request to Auth.currentCredentials, Auth.currentUserInfo, Auth.currentUserCredentials etc... The error in the screenshot can be reproduced making that request.
Code Snippet
Log output
aws-exports.js
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response