簡體   English   中英

AWS Amplify Auth - 獲取已登錄用戶的用戶屬性時出錯

[英]AWS Amplify Auth - Error when fetching user attributes of a signed in user

我正在嘗試在我的Android應用程序中使用AWS Amplify Auth 注冊和登錄有效,現在我正在嘗試獲取已登錄用戶的用戶屬性,但 Amplify 在Amplify.Auth.fetchUserAttributes() function 中拋出異常。

我的登錄代碼:

private void login(String email, String password) {
        Amplify.Auth.signIn(
                email,
                password,
                result -> {
                    if (result.isSignInComplete()) {
                        Log.i(TAG, "Sign in succeeded");
                        Log.i(TAG, "going to fetch User attributes");
                        
                            Amplify.Auth.fetchUserAttributes(
                                    attributes -> Log.i("AuthDemo", "User attributes = " + attributes.toString()),
                                    error -> Log.e("AuthDemo", "Failed to fetch user attributes.", error)
                            );

                        Log.i(TAG, "end of fetching User attributes");
                    } else {
                        Log.i(TAG,  "Sign in not complete");
                    }

                },
                error -> Log.e(TAG, error.toString())
        );
    }

日志:

I/LoginActivity: Sign in succeeded
W/InternalCallback: Library attempted to call user callback twice, expected only once
I/LoginActivity: going to fetch User attributes
D/AWSMobileClient: Inspecting user state details
D/AWSMobileClient: waitForSignIn: userState:SIGNED_OUT
E/AuthDemo: Failed to fetch user attributes.
    AuthException{message=Failed to fetch user attributes, cause=java.lang.Exception: Operation requires a signed-in state, recoverySuggestion=Ensure that you are logged in and online}
        at com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin$15.onError(AWSCognitoAuthPlugin.java:736)
        ....
     Caused by: java.lang.Exception: Operation requires a signed-in state
        ...

它告訴我用戶 state 是:SIGNED_OUT,但我在成功登錄方法中調用它,那么為什么用戶退出了?

請在 app -> src -> res -> raw -> amplifyconfiguration.json & awsconfiguration.json中檢查您的身份 poolId 是否正確(即使您沒有使用訪客訪問權限)。 您可以在您的 AWS 控制台中找到您的 poolId -> cognito -> 管理身份池 -> 單擊您的池 -> 單擊示例代碼:

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM