From 9b87258d2d8566d9481ec38032483211a96289f7 Mon Sep 17 00:00:00 2001 From: Igor Propisnov Date: Mon, 9 Sep 2024 15:58:53 +0200 Subject: [PATCH] w.i.p --- .../auth-module/controller/auth.controller.ts | 7 ++- .../auth-module/services/auth.service.ts | 11 ++-- .../welcome-root/welcome-root.component.html | 58 ++++++++++++++++++- .../welcome-root/welcome-root.component.ts | 20 ++++--- 4 files changed, 77 insertions(+), 19 deletions(-) diff --git a/backend/src/modules/auth-module/controller/auth.controller.ts b/backend/src/modules/auth-module/controller/auth.controller.ts index 182440e..d00da2f 100644 --- a/backend/src/modules/auth-module/controller/auth.controller.ts +++ b/backend/src/modules/auth-module/controller/auth.controller.ts @@ -53,9 +53,12 @@ export class AuthController { @HttpCode(HttpStatus.CREATED) @Public() public async signup( - @Body() userCredentials: UserCredentialsDto + @Body() userCredentials: UserCredentialsDto, + @Req() request: Request ): Promise { - return this.authService.signup(userCredentials); + const userAgent = request.headers['user-agent'] || 'Unknown'; + + return this.authService.signup(userCredentials, userAgent); } @ApiCreatedResponse({ diff --git a/backend/src/modules/auth-module/services/auth.service.ts b/backend/src/modules/auth-module/services/auth.service.ts index a4b9f78..23886fb 100644 --- a/backend/src/modules/auth-module/services/auth.service.ts +++ b/backend/src/modules/auth-module/services/auth.service.ts @@ -78,7 +78,8 @@ export class AuthService { } public async signup( - userCredentials: UserCredentialsDto + userCredentials: UserCredentialsDto, + userAgent: string ): Promise { try { const existingUser = await this.userCredentialsRepository.findUserByEmail( @@ -98,13 +99,9 @@ export class AuthService { passwordHashed ); - await this.userDataRepository.createInitialUserData(user); + await this.sendMagicLink({ email: user.email }, userAgent); - // TODO: Send Welcome Mail - // const token = - // await this.emailVerificationService.generateEmailVerificationToken( - // user.id - // ); + await this.userDataRepository.createInitialUserData(user); return { success: true, diff --git a/frontend/src/app/pages/welcome-root/welcome-root.component.html b/frontend/src/app/pages/welcome-root/welcome-root.component.html index 820dd04..8dd92a7 100644 --- a/frontend/src/app/pages/welcome-root/welcome-root.component.html +++ b/frontend/src/app/pages/welcome-root/welcome-root.component.html @@ -422,7 +422,7 @@
@@ -549,3 +549,59 @@
+ + + +
+
+ +
+
diff --git a/frontend/src/app/pages/welcome-root/welcome-root.component.ts b/frontend/src/app/pages/welcome-root/welcome-root.component.ts index a864200..c435ae8 100644 --- a/frontend/src/app/pages/welcome-root/welcome-root.component.ts +++ b/frontend/src/app/pages/welcome-root/welcome-root.component.ts @@ -24,7 +24,7 @@ import { Router } from '@angular/router'; import { ButtonModule } from 'primeng/button'; import { InputTextModule } from 'primeng/inputtext'; -import { delay, finalize, switchMap, takeWhile, tap, timer } from 'rxjs'; +import { delay, finalize, of, switchMap, takeWhile, tap, timer } from 'rxjs'; import { Configuration, @@ -80,6 +80,7 @@ export class WelcomeRootComponent implements OnInit { public isEmailSent: WritableSignal = signal(false); public displaySkeleton: WritableSignal = signal(false); public isVerifying: WritableSignal = signal(false); + public isUserSignupSuccessfully: WritableSignal = signal(false); public isTokenVerified: WritableSignal = signal(false); public errorReasons: WritableSignal = signal([]); public verificationError: WritableSignal = signal< @@ -132,16 +133,17 @@ export class WelcomeRootComponent implements OnInit { .pipe( switchMap(() => this.authService.status()), takeWhile((response: SuccessDtoApiModel) => response.success, true), - tap({ - next: (response: SuccessDtoApiModel) => { - if (response.success) { - this.router.navigate(['/dashboard']); - } - }, + switchMap((response: SuccessDtoApiModel) => { + if (response.success) { + return this.router.navigate(['/dashboard']).then(() => response); + } + return of(response); }), finalize(() => { this.isAutoLoginInProgress.set(false); - this.displaySkeleton.set(false); + setTimeout(() => { + this.displaySkeleton.set(false); + }, 100); }) ) .subscribe(); @@ -427,7 +429,7 @@ export class WelcomeRootComponent implements OnInit { .subscribe((response: SuccessDtoApiModel) => { if (response.success) { this.remeberUserMail(signupCredentials.email); - // Display Modal // You have successfully signed up. Please check your email for the magic link. + this.isUserSignupSuccessfully.set(true); } }); }