diff --git a/client/src/app/app.component.html b/client/src/app/app.component.html index 6ad5852607b4366d9b3e425b23e6c75091c51fb8..7f7773c6136e2b42e5d0fe06e1dd4d710274b9f0 100644 --- a/client/src/app/app.component.html +++ b/client/src/app/app.component.html @@ -7,6 +7,7 @@ <a href="/register">/register</a> <a href="/login">/login</a> <a href="/profile">/profile</a> + <a href="/logout">/logout</a> </nav> </div> diff --git a/client/src/app/authentication/auth.service.ts b/client/src/app/authentication/auth.service.ts index ce40111e461ff0348ecb1c7f2c12f5c7e0eea5a6..838b8f647ecc82a43bbf4108cb1e01b0c13b0434 100644 --- a/client/src/app/authentication/auth.service.ts +++ b/client/src/app/authentication/auth.service.ts @@ -66,6 +66,7 @@ export class AuthService { } logout() { localStorage.removeItem("token"); + this.router.navigateByUrl("/") } /** diff --git a/client/src/app/users/user-logout/user-logout.component.html b/client/src/app/users/user-logout/user-logout.component.html new file mode 100644 index 0000000000000000000000000000000000000000..c19d0971c67a067b2253f0a76550669e5c4311ec --- /dev/null +++ b/client/src/app/users/user-logout/user-logout.component.html @@ -0,0 +1 @@ +<p>user-logout works!</p> diff --git a/client/src/app/users/user-logout/user-logout.component.scss b/client/src/app/users/user-logout/user-logout.component.scss new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/client/src/app/users/user-logout/user-logout.component.spec.ts b/client/src/app/users/user-logout/user-logout.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..393de0aba04833b41f4e838b04e147da36718221 --- /dev/null +++ b/client/src/app/users/user-logout/user-logout.component.spec.ts @@ -0,0 +1,27 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { RouterTestingModule } from '@angular/router/testing'; +import { UserLogoutComponent } from './user-logout.component'; + +describe('UserLogoutComponent', () => { + let component: UserLogoutComponent; + let fixture: ComponentFixture<UserLogoutComponent>; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ UserLogoutComponent ], + imports: [ HttpClientTestingModule, RouterTestingModule ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(UserLogoutComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/client/src/app/users/user-logout/user-logout.component.ts b/client/src/app/users/user-logout/user-logout.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..e0e21b871ad106ef807fa87bb53859732ead5416 --- /dev/null +++ b/client/src/app/users/user-logout/user-logout.component.ts @@ -0,0 +1,17 @@ +import { Component, OnInit } from '@angular/core'; +import { AuthService } from 'src/app/authentication/auth.service'; + +@Component({ + selector: 'app-user-logout', + templateUrl: './user-logout.component.html', + styleUrls: ['./user-logout.component.scss'] +}) +export class UserLogoutComponent implements OnInit { + + constructor(private authService: AuthService) { } + + ngOnInit(): void { + this.authService.logout(); + } + +} diff --git a/client/src/app/users/user.module.ts b/client/src/app/users/user.module.ts index 3356ea2ac1b5d462dcfcf612be61cfd9899ba0bf..8d807898a3f435871ea9d79e61364c14e08e585c 100644 --- a/client/src/app/users/user.module.ts +++ b/client/src/app/users/user.module.ts @@ -5,6 +5,7 @@ import { FormsModule } from '@angular/forms'; import { UserRegistrationFormComponent } from './user-registration-form/user-registration-form.component'; import { UserProfileComponent } from './user-profile/user-profile.component'; import { UserLoginFormComponent } from './user-login-form/user-login-form.component'; +import { UserLogoutComponent } from './user-logout/user-logout.component'; @@ -12,7 +13,8 @@ import { UserLoginFormComponent } from './user-login-form/user-login-form.compon declarations: [ UserRegistrationFormComponent, UserProfileComponent, - UserLoginFormComponent + UserLoginFormComponent, + UserLogoutComponent ], imports: [ CommonModule,