From f18415bc290ef019a798e28a89902054684546d1 Mon Sep 17 00:00:00 2001 From: DaviMarinho Date: Thu, 16 Nov 2023 10:30:31 -0300 Subject: [PATCH] =?UTF-8?q?Quando=20o=20usu=C3=A1rio=20estiver=20logado=20?= =?UTF-8?q?n=C3=A3o=20consegue=20acessar=20login=20e=20registro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: DaviMarinho --- src/app/app-routing.module.ts | 11 ++++++----- src/app/services/no-token.guard.spec.ts | 16 ++++++++++++++++ src/app/services/no-token.guard.ts | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 src/app/services/no-token.guard.spec.ts create mode 100644 src/app/services/no-token.guard.ts diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index b1f37e8b..acf3597d 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -14,16 +14,17 @@ import { AuthGuard } from './services/auth.guard'; import { EditUserComponent } from './pages/edit-user/edit-user.component'; import { SuggestAgendaComponent } from './pages/suggest-agenda/suggest-agenda.component'; import { ParticipateComponent } from './pages/participate/participate.component'; +import { NoTokenGuard } from './services/no-token.guard'; const routes: Routes = [ - { path: 'login', component: LoginComponent }, - { path: 'register', component: RegisterComponent }, - { path: 'loginsocial', component: LoginSocialComponent }, + { path: 'login', component: LoginComponent, canActivate: [NoTokenGuard], }, + { path: 'register', component: RegisterComponent, canActivate: [NoTokenGuard], }, + { path: 'loginsocial', component: LoginSocialComponent, canActivate: [NoTokenGuard], }, + { path: 'sendCodeResetPassword', component: CheckCodeRestPasswordComponent, canActivate: [NoTokenGuard], }, + { path: 'changePassword', component: ResetPasswordComponent, canActivate: [NoTokenGuard], }, { path: 'videos', component: VideoComponent }, { path: 'video/:idVideo', component: VideoViewerComponent }, { path: 'activeAccount', component: ActiveAccountComponent }, - { path: 'sendCodeResetPassword', component: CheckCodeRestPasswordComponent }, - { path: 'changePassword', component: ResetPasswordComponent }, { path: 'suggestAgenda', component: SuggestAgendaComponent }, { path: 'participate', component: ParticipateComponent }, { path: 'profile', component: ProfileComponent, canActivate: [AuthGuard], }, diff --git a/src/app/services/no-token.guard.spec.ts b/src/app/services/no-token.guard.spec.ts new file mode 100644 index 00000000..da48db84 --- /dev/null +++ b/src/app/services/no-token.guard.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { NoTokenGuard } from './no-token.guard'; + +describe('NoTokenGuard', () => { + let guard: NoTokenGuard; + + beforeEach(() => { + TestBed.configureTestingModule({}); + guard = TestBed.inject(NoTokenGuard); + }); + + it('should be created', () => { + expect(guard).toBeTruthy(); + }); +}); diff --git a/src/app/services/no-token.guard.ts b/src/app/services/no-token.guard.ts new file mode 100644 index 00000000..39756b18 --- /dev/null +++ b/src/app/services/no-token.guard.ts @@ -0,0 +1,19 @@ +import { Injectable } from '@angular/core'; +import { CanActivate, Router } from '@angular/router'; +import { AuthService } from './auth.service'; + +@Injectable({ + providedIn: 'root' +}) +export class NoTokenGuard implements CanActivate { + constructor(private authService: AuthService, private router: Router) {} + + canActivate(): boolean { + if (!this.authService.isAuthenticated()) { + return true; + } else { + this.router.navigate(['/videos']); + return false; + } + } +}