Closed benjaminliang2 closed 1 year ago
Hi @benjaminliang2 do you know if you have unauthenticated/guest credentials allowed in your identity pool? If you do, currentUserCredentials
will return something for the guest credentials when you are not logged in.
I tried this on a react native app created with the CLI and thought I was experiencing the same thing until I noticed the identityId when signed out was different from the signed in. I then checked the identity pool and found I had guest credentials enabled.
This also led me to see that the 2 different users I tried looked similar at first glance but were not. I will investigate this further if you can confirm those things about your app
Also, which device did you try this on? I tried on iOS emulator and a real iOS device. Someone else tried on web and we were not able to reproduce what you are seeing so far. Each user has their own unique identityId and guest users have a new, random identityId when signed out
Hi @tannerabread, so I did have the "enable access to unauthenticated identities" checked, and i unchecked it. The behavior afterwards is somewhat expected but I still cant get the identityId
So if I execute:
await Auth.currentUserCredentials()
.then((cred) => console.log(cred))
.catch((err) => console.log("error: " + err));
It behaves as expected, but i do not see a identityId property. I also tried console.log(cred.identityId)
instead, but it just returns as "undefined".
I tried this on the web browser and my iPhone. I am using Expo Go for my phone. I start both with expo start
I also wanted to confirm my behavior when I still had "enable access to unauthenticated identities" checked. I double checked the data that's returned when calling
await Auth.currentUserCredentials()
.then((cred) => console.log(cred))
.catch((err) => console.log("error: " + err));
I get something like
Object {
[13:04:57] "accessKeyId": "XXXXZNXXXJV5SFHXXXXX",
[13:04:57] "authenticated": false,
[13:04:57] "expiration": 2023-02-18T00:04:56.000Z,
[13:04:57] "identityId": "us-east-1:c3f36508-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
[13:04:57] "secretAccessKey": "XXXX",
Whether I am authenticated or not, the identityId
and authenticated
status is the same. Eveything else is different. There is also the sessionToken
but I didnt check it as thats too long
That's some very interesting behavior. As no one has been able to reproduce this yet (after trying a few different apps/environments), would it be possible for you to provide a sample repo that demonstrates the behavior?
I set up a different branch on my projects repo for this problem.
https://github.com/benjaminliang2/calorie-tracker-mobile/tree/debug
The auth logic is in the src/navigation
folder, and
src/components/SignInScreen.js
src/components/SignUpScreen.js
I tried with your repo and get the expected result where authenticated
is false if I am not signed in, and the identityId
is constant for my logged in user and different when I am logged out.
How were you checking the logged out behavior?
From the branch "debug" that I cloned, logged out users only see the login screen, so I implemented a button on that screen to call the currentUserCredentials
function and did the same on the main page for signed in users
I am just using a try-catch block and console logging the result. I see the results in my gitbash terminal. In that case, I will try to implement this aws auth in a starter project. I am not sure whats happening with this current one.
Definitely let me know how that goes, I was wondering if maybe your resources got messed up somehow. Another route would be to take a clone of your own sample repo and try to amplify init
some new resources and see if it works that way
I was able to re-initialize amplify and auth
seems to be working so far. I assume my resources got messed up as I did try to implement federated identities before I even verified basic authentication was working.
Right now, basic signin, signup, and signout are working with the expected identityId
for unauth and authd users. Thank you for the help!!
Glad that worked! If you find that it happens again without touching your resources comment here so that we can figure out what happened.
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
Authentication, REST API
Amplify Categories
auth
Environment information
Describe the bug
Auth.currentUserCredentials().identityId
returns a value such as "us-east-1:xxx......." even if there is no authenticated user.Auth.currentAuthenticatedUser()
seems to be working as it returns an error when the user is not authenticated.Below is my code on app mount in react native
Furthermore, if i signin
user1
, callAuth.currentUserCredentials().identityId
, signoutuser1
, signinuser2
callAuth.currentUserCredentials().identityId
---the two values for two different users are the same. It seems that the credentials are not updated correctly.Expected behavior
I expect
Auth.currentUserCredentials()).identityId
to return an error or null when there is no user signed in.i expect
Auth.currentUserCredentials()).identityId
to return different values for different authenticated users.Reproduction steps
initalize react native project through expo with npx create-expo-app my-app
write signup form.
Include code snippet below in app.js
run expo start
setup a lambda pretrigger to autoconfirm user
sign a user up with
Auth.signUp({...})
.sign in user with
Auth.signIn()
sign out user with
Auth.signOut()
execute Auth.currentUserCredentials()
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