簡體   English   中英

錯誤您在預期 stream 的位置提供了“未定義”。 您可以提供一個 Observable、Promise、Array 或 Iterable,在 Cognito 中調用 refreshSession

[英]Error You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable, call refreshSession in Cognito

我正在嘗試刷新 AWS Cognito 中用戶的訪問令牌。 我收到錯誤消息:您在預期 stream 的地方提供了“未定義”。 您可以在第一次調用方法 refreshSession 后立即提供 Observable、Promise、Array 或 Iterable 我在 Angular 7 中使用 HttpInterceptor。下面是我的代碼:

public intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    // process the request
    return next.handle(request).pipe(
        catchError((httpError: any) => {
            // check if the error is a permission issue
            if (httpError instanceof HttpErrorResponse && httpError.status === 401 {
                const poolData = {
                    UserPoolId: <userPoolId>,
                    ClientId: <clientId>
                };
                const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
                const cognitoUser = userPool.getCurrentUser();
                if (cognitoUser != null) {
                    cognitoUser.getSession((error, session) => {
                        if (error) {
                            cognitoUser.signOut();
                            this.router.navigate(['/login']);
                        }
                        cognitoUser.refreshSession(session.refreshToken, (refreshError, refreshSession) => {
                            if (refreshError) {
                                cognitoUser.signOut();
                                this.router.navigate(['/login']);
                            }
                            // set the cognito credentials
                            AWS.config.credentials = new AWS.CognitoIdentityCredentials({
                                IdentityPoolId: this.identityPoolId,
                                Logins: { [`cognito-idp.${<region>}.amazonaws.com/${<userPoolId>}`]: refreshSession.getIdToken().getJwtToken() }
                            });
                            (AWS.config.credentials as AWS.Credentials).refresh(err => {
                                if (err) {
                                    cognitoUser.signOut();
                                    this.router.navigate(['/login']);
                                }
                            });
                        });
                    });
                }
            } else {
                return of(httpError);
            }
        })
    );
}

在您的catchError中, function 僅在else子句中返回一個可觀察的( of(httpError) )。 如果錯誤是 401,則沒有返回(即undefined )。即使您不關心返回值(在這種情況下, of(null)EMPTY應該這樣做),也在那里返回一些東西。

暫無
暫無

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

相關問題 您提供了“未定義”的預期流。 您可以提供一個Observable,Promise,Array或Iterable 類型錯誤:您在需要流的地方提供了“未定義”。 你可以提供一個 Observable、Promise、Array 或 Iterable 錯誤類型錯誤:您在需要流的地方提供了“空”。 你可以提供一個 Observable、Promise、Array 或 Iterable 錯誤:“您在需要流的地方提供了 &#39;undefined&#39;。您可以提供 Observable、Promise、Array 或 Iterable。” 在我的身份驗證攔截器中 如何修復“錯誤:您在預期流的位置提供了‘未定義’。您可以提供 Observable、Promise、Array 或 Iterable”? 錯誤類型錯誤:您在需要流的地方提供了“未定義”。 您可以在 Angular 服務中提供 Observable、Promise、Array 或 Iterable 類型錯誤:您提供了一個預期流的無效對象。 你可以提供一個 Observable、Promise、Array 或 Iterable Angular:您在需要流的地方提供了一個無效的對象。 你可以提供一個 Observable、Promise、Array 或 Iterable xplat您提供了一個無效的對象,該對象應在其中流。 您可以提供一個Observable,Promise,Array或Iterable Rxjs 6:使用catchError()可以為您提供“未定義”的預期流。 您可以提供一個Observable,Promise,Array或Iterable
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM