diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index 41d58d9..bbb5677 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -24,6 +24,7 @@ export const routes: Routes = [ children: [ { path: '', component: LoginComponent, pathMatch: 'full' }, { path: 'login', component: LoginComponent }, + { path: 'logout', component: LoginComponent }, { path: 'login/notice/:id', component: LoginComponent }, { path: 'register', component: RegisterComponent }, { path: 'forgot-pw', component: ForgotPwComponent }, diff --git a/src/app/components/login/login.component.ts b/src/app/components/login/login.component.ts index 212f6db..d8aff95 100644 --- a/src/app/components/login/login.component.ts +++ b/src/app/components/login/login.component.ts @@ -78,6 +78,7 @@ export class LoginComponent { try { await this.authService.login(this.loginData, this.checkboxRememberMe); this.router.navigate(['/summary']); + this.sharedService.isBtnDisabled = false; } catch (error) { this.sharedService.isBtnDisabled = false; const errorMessage = this.errorHandlingService.handleHttpError(error); diff --git a/src/app/guards/redirect-if-authenticated.guard.ts b/src/app/guards/redirect-if-authenticated.guard.ts index c83b803..25fbf1e 100644 --- a/src/app/guards/redirect-if-authenticated.guard.ts +++ b/src/app/guards/redirect-if-authenticated.guard.ts @@ -24,7 +24,6 @@ export class RedirectIfAuthenticatedGuard { return this.authService.checkAuthUser().pipe( map((isAuthenticated) => { if (isAuthenticated) { - this.router.navigate(['/summary']); return false; } return true; diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 440945f..41dfa61 100755 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -10,6 +10,8 @@ import { import { ApiService } from './api.service'; import { TokenService } from './token.service'; import { ErrorHandlingService } from './error-handling.service'; +import { ToastrService } from 'ngx-toastr'; +import { Router } from '@angular/router'; @Injectable({ providedIn: 'root', @@ -20,7 +22,9 @@ export class AuthService { constructor( private apiService: ApiService, private tokenService: TokenService, - private errorHandlingService: ErrorHandlingService + private errorHandlingService: ErrorHandlingService, + private toastrService: ToastrService, + private router: Router ) { this.currentUserIdSubject.next(this.tokenService.getUserId()); } @@ -38,6 +42,7 @@ export class AuthService { this.tokenService.storeAuthToken(token, storage); this.tokenService.storeUserId(userId, storage); this.currentUserIdSubject.next(userId); + this.showLoginSuccessMessage(); } catch (error) { console.error('Login failed:', error); throw new Error(this.errorHandlingService.handleHttpError(error)); @@ -51,7 +56,8 @@ export class AuthService { this.tokenService.deleteAuthToken(); this.tokenService.deleteUserId(); this.currentUserIdSubject.next(null); - window.location.href = '/login'; + this.showLogoutSuccessMessage(); + this.router.navigate(['/logout']); } catch (error) { console.error('Logout failed:', error); throw new Error(this.errorHandlingService.handleHttpError(error)); @@ -68,4 +74,24 @@ export class AuthService { getCurrentUserId(): Observable { return this.currentUserIdSubject.asObservable(); } + + private showLoginSuccessMessage() { + this.toastrService.success( + 'You have successfully logged in.', + 'Login Successful', + { + timeOut: 3000, + } + ); + } + + private showLogoutSuccessMessage() { + this.toastrService.info( + 'You have successfully logged out. Have a nice day!', + 'Logout Successful', + { + timeOut: 3000, + } + ); + } }