Reputation: 964
I am using react-native and the out of the box aws-amplify-react-native to sigin, signup users. Users are able to authenticate successfully but getting the following error in the signin form "no current user"
I pumped up the log level to debug in the application. I can see the user successfully authenticate and I get back the JWT token but I see the following in the logs:
[DEBUG] 22:47.149 AuthClass - Failed to get user from user pool
[ERROR] 22:47.154 AuthClass - Failed to get the signed in user No current user
[DEBUG] 22:47.161 AuthPiece - No current user
Below is a snippet of my code:
import { ConfirmSignIn, ConfirmSignUp, ForgotPassword, RequireNewPassword, SignIn, SignUp, VerifyContact, withAuthenticator } from 'aws-amplify-react-native';
const RootStack = createStackNavigator(
{
Login: LoginScreen,
Main: MainScreen,
Customer: CustomerScreen,
Reports: ReportsScreen,
Signup: SignupScreen
},
{
initialRouteName: 'Main',
}
);
const AppContainer = createAppContainer(RootStack);
export class App extends React.Component {
render() {
return (
<AppContainer />
);
}
}
export default withAuthenticator(App);
When I run my app. I see the default Sign In form for Amplify, I use it to enter username and password and then click on "SIGN IN" button which does successfully authenticate but I get the "No current user error" as shown above.
Upvotes: 12
Views: 15310
Reputation: 1
resolved
Togle "secure" to true in config:
Auth: { region: "us-west-2", userPoolId: "us-west-2_xxxxx", userPoolWebClientId: "xxxxxx", cookieStorage: { domain: "localhost", path: "/", expires: 5, secure: true, // <------------------------ true },
Upvotes: 0
Reputation: 11
I had this issue and I was able to sort it out by making the password of the user permanent with the command:
aws cognito-idp admin-set-user-password --user-pool-id us-east-1_XXX --username XXXXX --password XXXX --permanent
Upvotes: 1
Reputation: 830
The error is literally saying No current user
- you need to sign in using the supported identity provider.
My solution to that:
import { Amplify } from "@aws-amplify/core";
import { Auth } from "@aws-amplify/auth";
import { CookieStorage } from 'amazon-cognito-identity-js';
import amplifyConfig from "../lib/Amplify";
Amplify.configure(amplifyConfig);
const cookieStorage = new CookieStorage(amplifyConfig.Auth.cookieStorage);
// cookie that is set before Cognito redirect to prevent infinite loop if authorization fails due to other reason than "No current user"
const redirectedFromAuthorize = cookieStorage.getItem("redirected-from-authorize");
...
Auth.currentAuthenticatedUser()
.then(user => {
setUser(user); // your custom function to do something with user attributes
// authorization was successfull, we can remove the redirect cookie
cookieStorage.removeItem("redirected-from-authorize");
})
.catch(err => {
console.error(err);
// if the cookie is set, it means the authorization failed again and you should not redirect back to Cognito
if (!redirectedFromAuthorize) {
// set redirect cookie, so that we know next time the error is reocurring
cookieStorage.setItem("redirected-from-authorize", 'true');
// redirect to Cognito hosted UI
return Auth.federatedSignIn();
}
});
Upvotes: 2
Reputation: 161
I had the similar problem. I removed the cookie storage block from the configure method and it worked.
Upvotes: 16
Reputation: 51
Are you using the cookieStore? If true, do you use the secure flag? If so, change its value to false
in the development environment.
Upvotes: 5