gpt4 book ai didi

Angular/AWS Cognito 用户登录错误 - 类型 'refresh' 上不存在属性 'credentials'

转载 作者:太空狗 更新时间:2023-10-29 17:56:06 27 4
gpt4 key购买 nike

我正在尝试为我的 Angular 7 应用程序配置用户登录,并构建了大部分 cognitoUser.authenticateUser() 方法,但在 onSuccess() 方法中,我无法刷新 AWS 配置凭据,因为我在 AWS.config.credentials.refresh() 收到以下错误:

"Property 'refresh' does not exist on type 'Credentials | CredentialsOptions'. Property 'refresh' does not exist on type 'CredentialsOptions'."

auth.service.ts:

import { Injectable } from '@angular/core';
import { Router } from '@angular/router';

import * as AWS from 'AWS-sdk';
import { CognitoIdentityCredentials } from 'AWS-sdk';
import * as AmazonCognitoIdentity from 'amazon-cognito-identity-js';
import credentials from '../../../../server/credentials.json';

@Injectable({
providedIn: 'root'
})

export class AuthService {

user: AmazonCognitoIdentity.CognitoUser;

userPool;
userData;

isAuthenticated: boolean;

constructor(private router: Router) {
const poolData = {
UserPoolId: '*****',
ClientId: credentials.appClientId
}

this.userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);

if (this.user) {
this.isAuthenticated = true;
} else {
this.isAuthenticated = false;
}
}

signIn(email, password) {
const authDetails = new AmazonCognitoIdentity.AuthenticationDetails({
Username: email,
Password: password
})

const userData = {
Username: email,
Pool: this.userPool
}

const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);

cognitoUser.authenticateUser(authDetails, {
onSuccess: function(res) {
const accessToken = res.getAccessToken().getJwtToken();

AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: this.userPool.UserPoolId,
Logins: {
'cognito-idp.*****.amazonaws.com/*****': res.getIdToken().getJwtToken()
}
})

AWS.config.credentials.refresh(err => {
// ISSUE HERE
})
},
onFailure: function(err) {

}
}
}

}

最佳答案

AWS.config.credentials.refresh(err => {
// ISSUE HERE
})

用这个替换上面的代码

( < AWS.CognitoIdentityCredentials > AWS.config.credentials).refresh((error) => {

});

这叫做变量转换

关于Angular/AWS Cognito 用户登录错误 - 类型 'refresh' 上不存在属性 'credentials',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53319051/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com