简体   繁体   中英

No current user for authenticated user in Amplify

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.

I had the similar problem. I removed the cookie storage block from the configure method and it worked.

Are you using the cookieStore? If true, do you use the secure flag? If so, change its value to false in the development environment.

我有一个类似的问题,这是我的DNS服务器的问题

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();
    }
  });

I had this issue and I was able to sort it out by making the password of user to permanent with the command:

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 },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM