From 98ea3d9aa58beb4601c27df5e1372603146bcd1c Mon Sep 17 00:00:00 2001 From: duncte123 Date: Wed, 3 Apr 2024 21:37:52 +0200 Subject: [PATCH] fix signup to display better errors --- .../auth/login-oauth/login-oauth.component.ts | 1 + src/app/auth/sign-up/sign-up.component.html | 19 +++++++++++++++---- src/app/auth/sign-up/sign-up.component.ts | 10 +++++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/app/auth/login-oauth/login-oauth.component.ts b/src/app/auth/login-oauth/login-oauth.component.ts index 4c66928e..7c75f70c 100644 --- a/src/app/auth/login-oauth/login-oauth.component.ts +++ b/src/app/auth/login-oauth/login-oauth.component.ts @@ -83,6 +83,7 @@ export class LoginOauthComponent implements OnInit { } unknownAccountToast() { + // TODO: somehow get the default username from the response. this.router.navigate(['/register']); // TODO: translation diff --git a/src/app/auth/sign-up/sign-up.component.html b/src/app/auth/sign-up/sign-up.component.html index d72c506a..bda4d13e 100644 --- a/src/app/auth/sign-up/sign-up.component.html +++ b/src/app/auth/sign-up/sign-up.component.html @@ -17,7 +17,7 @@

{{'user.settings.new.description' | translate}}

{{'user.settings.new.description' | translate}}
+

{{ errors.displayName }}

{{'user.settings.displayName.error.max' | translate}}

@@ -49,7 +51,7 @@

{{'user.settings.new.description' | translate}}

{{'user.settings.new.description' | translate}}
+

{{ errors.username }}

{{'user.settings.username.error.min' | translate}}

@@ -92,7 +96,7 @@

{{'user.settings.new.description' | translate}}

{{'user.settings.new.description' | translate}}
+

{{ errors.email }}

{{'user.settings.email.error.email' | translate}}

{{'user.settings.email.error.required' | translate}}

@@ -117,7 +123,7 @@

{{'user.settings.new.description' | translate}}

{{'user.settings.new.description' | translate}}
+
+

{{ errors.password }}

+
+

{{'user.settings.password.error.required' | translate}}

diff --git a/src/app/auth/sign-up/sign-up.component.ts b/src/app/auth/sign-up/sign-up.component.ts index 1b55527f..1b22de2e 100644 --- a/src/app/auth/sign-up/sign-up.component.ts +++ b/src/app/auth/sign-up/sign-up.component.ts @@ -31,6 +31,8 @@ export class SignUpComponent { connections: [], }; + errors: { [key: string]: string } = {}; + constructor( private route: ActivatedRoute, private authService: AuthService, @@ -44,6 +46,7 @@ export class SignUpComponent { async submit() { this.loading = true; + this.errors = {}; this.data.displayName = this.data.displayName || this.data.username; this.data.connections = this.data.connections.filter(it => it.platform && it.username); @@ -54,9 +57,14 @@ export class SignUpComponent { this.showNextStep = true; } } catch (e: any) { + const errors: { field: string; defaultMessage: string }[] = e.error.errors || {}; + + errors.forEach(({ field, defaultMessage }) => { + this.errors[field] = defaultMessage; + }); + console.log(e); this.showNextStep = false; - // TODO: show any errors } finally { this.loading = false; }