AWS放大登录,注册并确认签名工作流程问题

时间:2019-04-15 19:35:52

标签: angular amazon-cognito aws-amplify

我已经在angular项目中实现了AWS-Amplify,并且在注册,签名后确认用户的工作情况都很好,但是我遇到了流程方面的问题,并且我试图找到一个解决方案围绕它,我的问题是,当用户注册时,他将被重定向到确认页面以输入确认代码,提交代码后,用户必须登录才能访问我的网站,因此我试图尝试登录用户成功注册并确认帐户后直接解决,但无法解决,这是我的注册代码:

onSubmitSignup(value: any) {
    const email = value.email, password = value.password;
    let attributes: {
        username,
        phone_number,
    };
    this.auth.signUp(email, password, attributes)
        .subscribe(
            result => {
                this.successfullySignup = true;
                this.router.navigate(['/pages/confirmRegistration', result.user.username]);
            },
            error => {
                console.log(error);
                this.errorMessage = error.message;
            });
}

并在我的身份验证服务中:

public signUp(email, password, userAttributes): Observable<any> {
    return fromPromise(Auth.signUp(email, password, userAttributes));
}

这是确认用户的代码:

onSubmitConfirmation(value: any) {
    const email = this.email, confirmationCode = value.confirmationCode;
    this.auth.confirmSignUp(email, confirmationCode)
        .subscribe(
            result => {
                this.auth.signIn(this.email, this.password); //this what im trying to achieve is to have the user data from the sign in and sign up components here in the confirmation component 
            },
            error => {
                console.log(error);
                this.errorMessage = error.message;
            });
}

及其服务:

public confirmSignUp(email, code): Observable<any> {
    return fromPromise(Auth.confirmSignUp(email, code));
}

我的登录方法:

onSubmitLogin(value: any) {
  const email = value.email, password = value.password;
  this.auth.signIn(email, password)
    .subscribe(
      result => {
        this.router.navigate(['']);
      },
      error => {
        this.errorMessage = error.message;
        if (error.code === 'UserNotConfirmedException') {
          this.router.navigate(['/pages/confirmRegistration']);
        }
      });
}

及其服务:

public signIn(email, password): Observable<any> {
    return fromPromise(Auth.signIn(email, password))
        .pipe(
            tap(() => this.loggedIn.next(true))
        );
}

尽管我希望将用户名和密码作为我所有身份验证组件之间的共享数据,然后使用它们,但是认为这不是一个好习惯,并且无法实现,所以如果可以建议一种更好的方法你能建议吗?我虽然使用以下方式传递电子邮件和密码:

this.router.navigate(['/pages/confirmRegistration', result.user.username]);

但是这会将密码公开在url中,我认为这不是一个好主意,我不是专家,但是如果可以的话请告知。

我什至考虑过在每个signIn和signUp的相同组件中使用确认方法,但这将复制代码,但是在确认用户后我可能能够访问登录所需的字段。

0 个答案:

没有答案
相关问题