Skip to content

Commit

Permalink
Quando o usuário estiver logado não consegue acessar login e registro
Browse files Browse the repository at this point in the history
Signed-off-by: DaviMarinho <[email protected]>
  • Loading branch information
DaviMarinho committed Nov 16, 2023
1 parent 0706173 commit f18415b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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], },
Expand Down
16 changes: 16 additions & 0 deletions src/app/services/no-token.guard.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
19 changes: 19 additions & 0 deletions src/app/services/no-token.guard.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit f18415b

Please sign in to comment.