#javascript #node.js #typescript #amazon-cognito
#javascript #node.js #typescript #amazon-cognito
Вопрос:
По какой-то причине элемент управления не вводит cognito authenticate в мой API, хотя я предоставляю все значения. Это работало в моей рабочей системе, но когда оно перестало работать в другой системе. Ниже приведен код, который вызывает мою функцию аутентификации (функция аутентификации вызывается из функции входа в систему:
export class UserCAO {
private poolData;
private CognitoUserPool: AmazonCognitoIdentity.CognitoUserPool;
private pool_region: string;
private userPool;
private cognitoUser: AmazonCognitoIdentity.CognitoUser;
private companyID: string;
constructor() {
this.poolData = {
UserPoolId: process.env.COGNITO_USER_POOL_ID,
ClientId: process.env.COGNITO_CLIENT_ID
}
this.pool_region = process.env.COGNITO_POOL_REGION!;
this.userPool = new AmazonCognitoIdentity.CognitoUserPool(this.poolData);
}
public async login(req: UserLoginRequest): Promise<object> {
return new Promise<any>(async (resolve, reject) => {
console.log(`This is the req password-----> ${req.password}`)
try {
var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails({
Username: req.emailAddress,
Password: req.password
});
var userData = {
Username: req.emailAddress,
Pool: this.userPool
};
this.cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
await this.authenticateUser(this.cognitoUser, authenticationDetails).then(value=> {
resolve(value)
}).catch(error => {
console.log(`This is the login error catch----> ${JSON.stringify(error)}`)
});
} catch (error) {
console.log(`I entered into the catch of try block ${JSON.stringify(error)}`)
reject(error);
}
});
}
И это мой метод аутентификации:
private async authenticateUser(cognitoUser: AmazonCognitoIdentity.CognitoUser, authenticationDetails: AmazonCognitoIdentity.AuthenticationDetails) {
console.log(`Inside authenticate user`);
console.log(`This is the cognitoUser in the auth function -----> ${JSON.stringify(cognitoUser)} and tehse are the authentication details-----> ${JSON.stringify(authenticationDetails)}`)
return new Promise<any>(async (resolve, reject) => {
try{
console.log(`Trying man!.....`); //<-- This gets logged . But then directly goesd to the catch block
await cognitoUser.authenticateUser(authenticationDetails, { //<--- The control doesn't enter this function. It directly flows to the catch block of try
onSuccess: (result) => {
console.log(`This is the success result ----> ${JSON.stringify(result)}`);
resolve(result)
},
onFailure: (error) => {
console.log(`This is the error being returned in onFailure ----> ${JSON.stringify(error)}`)
resolve(error)
}
})
}
catch(error){
console.log(`This is the error from authenticate try catch block ${JSON.stringify(error)}`);
reject(error);
}
})
}
Комментарии:
1. Укажите
JSON.stringify(error)
значение.2. Я получаю null. Но я только что исправил эту проблему и застрял с другой. Решение было здесь github.com/aws-amplify/amplify-js/issues /…