angular - Aws 放大登录、注册和确认签名工作流程问题
问题描述
我已经在 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 的相同组件中使用确认方法,但这会重复代码,但在确认用户后我可能能够访问登录所需的字段。
解决方案
推荐阅读
- python - Python 3 Count 在函数内更新,但值不会在函数外更新
- android - RecyclerView 在日志中显示 Null 值但没有错误
- python - 使用 Sequential API 从 Keras 自动编码器中提取编码/解码模型
- python-3.x - IBM 树莓派物联网服务
- powerapps - 如何在 Powerapps 中同时使用 collect 和 if 函数?
- r - 每隔一行拆分变量以在 data.frame 中形成两个新列
- android - 根据屏幕Android Studio在GridLayout中设置按钮的宽度和高度
- python - 如何强制 Python 导航到网页并打印所有锚点(a-html)
- java - 将 3 个链表合并为 1 个(Java)
- javascript - 如何在加载网页时隐藏 div