Skip to content

Commit

Permalink
added logout to the page
Browse files Browse the repository at this point in the history
  • Loading branch information
Gururajj77 committed Jan 14, 2024
1 parent c725aa6 commit 139080f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/app/shared/components/header/header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@
Profile
</li>
</ul>
<img
class="logout"
(click)="logout()"
src="../../../../assets/logout.svg"
alt="logout"
/>
</nav>
10 changes: 10 additions & 0 deletions src/app/shared/components/header/header.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
cursor: pointer;
}
}

.logout {
width: 20px;
height: 20px;
color: $inactive-color;
cursor: pointer;
&:hover {
filter: drop-shadow(1px 1px 1px rgba(0, 0, 0, 0.3));
}
}
@media (max-width: 768px) {
.header {
justify-content: space-between;
Expand Down
13 changes: 13 additions & 0 deletions src/app/shared/components/header/header.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Component, inject } from '@angular/core';
import { Auth } from '@angular/fire/auth';
import { Router, RouterModule } from '@angular/router';
import { SnackbarService } from '../snackbar/snackbar.service';

@Component({
selector: 'app-header',
Expand All @@ -11,9 +13,20 @@ import { Router, RouterModule } from '@angular/router';
export class HeaderComponent {

private readonly router: Router = inject(Router);
private readonly auth: Auth = inject(Auth);
private readonly snackbarService: SnackbarService = inject(SnackbarService);

toHome() {
this.router.navigateByUrl('/app/feed');
}

async logout() {
try {
await this.auth.signOut();
this.router.navigateByUrl('/sign-in');
} catch (error) {
this.snackbarService.show('Logout Failed');
}
}

}
2 changes: 1 addition & 1 deletion src/app/sign-in/sign-in.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class SignInComponent {
try {
const { email, password } = this.loginForm.value;
await signInWithEmailAndPassword(this.auth, email, password);
this.snackbarService.show('Signed In Successfully', 5000);
this.snackbarService.show('Signed In Successfully', 2500);
this.router.navigateByUrl('app/feed');
} catch (error: any) {
this.ERROR_CODE = error.code;
Expand Down
2 changes: 1 addition & 1 deletion src/app/sign-up/sign-up.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, inject } from '@angular/core';
import { Auth, GoogleAuthProvider, createUserWithEmailAndPassword, signInWithPopup, updateProfile, user } from '@angular/fire/auth';
import { Auth, GoogleAuthProvider, createUserWithEmailAndPassword, signInWithPopup, updateProfile } from '@angular/fire/auth';
import { Router } from '@angular/router';
import { FormBuilder, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { FirestoreService } from '../shared/services/firestore/firestore.service';
Expand Down
3 changes: 3 additions & 0 deletions src/assets/logout.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 139080f

Please sign in to comment.