aws Amplify와 함께 사용자 정의 UI를 사용하려고하는데 Auth.completeNewPassword에 문제가 있습니다. 이 방법을 사용하려고하면
Error in v-on handler: "TypeError: Cannot read property 'username' of null
오류가 발생합니다.
.
이전에 주어진 UI를 사용해 본 결과, 관리자가 Cognito 사용자를 만들면 처음 로그인 할 때 '새 비밀번호'양식으로 전송된다는 것을 알고 있습니다. 그러나 Amplify 문서의 예제에는 사용자가 새 비밀번호가 필요한 것을 발견하면 signNew 메소드가 completeNewPassword 메소드를 즉시 호출합니다.
다음 스 니펫은 Amazon 문서에서 직접 가져온 것입니다.
import { Auth } from 'aws-amplify';
Auth.signIn(username, password)
.then(user => {
if (user.challengeName === 'NEW_PASSWORD_REQUIRED') {
const { requiredAttributes } = user.challengeParam; // the array of required attributes, e.g ['email', 'phone_number']
Auth.completeNewPassword(
user, // the Cognito User Object
newPassword, // the new password
// OPTIONAL, the required attributes
{
email: '[email protected]',
phone_number: '1234567890'
}
).then(user => {
// at this time the user is logged in if no MFA required
console.log(user);
}).catch(e => {
console.log(e);
});
} else {
// other situations
}
}).catch(e => {
console.log(e);
});
동일한 TypeError 결과로 몇 가지 다른 방법으로 시도했습니다. completeNewPassword 메서드를 개별적으로 호출하고 사용자를 변수로 저장하고 전달한 다음 다시 로그인하여 completeNewPassword 등에 해당 사용자를 전달하면 상관 없습니다. 매번 같은 TypeError.
예를 들어, 다음 방법은 로그인 버튼을 처음 클릭 할 때 '사용자'개체를 올바르게 기록하지만 새 비밀번호를 제출하려고 할 때 동일한 버튼을 클릭하면 해당 줄 이전에 실패합니다.
signIn () {
Auth.signIn(this.user_name, this.password)
.then(user => {
if (user.challengeName === 'NEW_PASSWORD_REQUIRED') {
console.log(user)
const { requiredAttributes } = user.challengeParam;
this.$parent.$parent.pageStatus.passwordSetPanel = true;
Auth.completeNewPassword(
user,
this.newPassword
)
}
})
},
추가 정보 :
<올>수정
이 코드로 반 작업 솔루션을 찾도록 관리했습니다 :
signIn () {
this.$parent.$parent.pageStatus.loginPanel = false;
this.$parent.$parent.loading = true;
Auth.signIn(this.user_name, this.password)
.then(async user => {
if (user.challengeName === 'NEW_PASSWORD_REQUIRED') {
const loggedUser = await Auth.completeNewPassword(
user,
this.password,
)
this.$parent.$parent.pageStatus.passwordSetPanel = true
}
})
}
이것은 사용자를 업데이트하기 위해 관리하지만 암호를 this.password (원래 변경 될 암호)로 설정해야 작동합니다. 문제는 Amplify가 동일한 기능을 사용하여 signIn과 completeNewPassword를 호출하기를 원한다는 것입니다. 그러나 이러한 UI는 두 개의 다른 패널로 분할되어야합니다.
- 답변 # 1
관련 자료
- javascript - 이 코드에서 'google not defined'오류와 'typeerror - cannot read property'placesservice 'of undefined at initialize'가 발생하는
- python - typeerror - django에서 일관된 메서드 해결을 만들 수 없습니다
- python - typeerror - 'method'객체는 정수로 해석 될 수 없습니다
- java - `size ()`메소드를 실행하려고 할 때 'ConcurrentModificationException'을 발생시키는 ArrayList
- c# - 토큰을 가져 오는 중에 사용자 자격 증명 오류가 발생하는 AcquireToken 메서드
- reactjs - 왜 이것이 TypeError가 발생합니까?
- javascript - arraypush에 대한 TypeError를 던지는 Arraypush는 함수가 아닙니다
- java : AWS DynamoDbmapper 저장 방법은`dynamodbmappingException : 지원되지 않음; @dynamodbtyped 또는 @ dynamodbtypeConverted`가 필요합니다
이것은 끔찍한 해킹이지만, completeNewPassword 패널을 위해 사용자 약속, 이름 및 일반 텍스트 비밀번호를 임시 js 변수에 저장하여 해결 방법을 찾았습니다. 더 나은 솔루션을 아는 사람이 있으면 언제든지 게시하십시오.