【问题标题】:No current user for authenticated user in AmplifyAmplify 中没有经过身份验证的用户的当前用户
【发布时间】:2019-04-03 14:32:53
【问题描述】:

我正在使用 react-native 和开箱即用的 aws-amplify-react-native 来注册用户。用户能够成功进行身份验证,但在登录表单“没有当前用户”中出现以下错误

我提高了日志级别以在应用程序中进行调试。我可以看到用户成功验证并取回了 JWT 令牌,但我在日志中看到以下内容:

[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

下面是我的代码的 sn-p:

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

当我运行我的应用程序时。我看到 Amplify 的默认登录表单,我使用它输入用户名和密码,然后单击“登录”按钮,该按钮成功通过身份验证,但我收到“无当前用户错误”,如上所示。

【问题讨论】:

    标签: amazon-web-services react-native aws-amplify


    【解决方案1】:

    我遇到了类似的问题。我从 configure 方法中删除了 cookie 存储块并且它起作用了。

    【讨论】:

    • 我还删除了现有的 cookie,上述解决方案有效
    • 该解决方案也对我有用。那么这是否意味着我们不应该使用 cookie 存储来响应本机应用程序?还是仅在开发环境中存在问题,或者我们应该将其包含回来以供发布??
    • 这解决了我的问题!谢谢!
    【解决方案2】:

    您在使用 cookieStore 吗?如果为真,您是否使用安全标志?如果是这样,在开发环境中将其值更改为false

    【讨论】:

      【解决方案3】:

      错误的字面意思是No current user - 您需要使用受支持的身份提供者登录。

      我的解决方案:

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

      【讨论】:

        【解决方案4】:

        我遇到了这个问题,我可以通过使用以下命令使用户的密码永久化来解决它:

        aws cognito-idp admin-set-user-password --user-pool-id us-east-1_XXX --username XXXXX --password XXXX  --permanent
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-11-15
          • 2016-01-17
          • 2020-12-22
          • 1970-01-01
          • 1970-01-01
          • 2020-11-24
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多