Skip to content

Commit f328f22

Browse files
committed
feat(package): added ngx-auth-firebaseui-avatar component
1 parent 2098d3e commit f328f22

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

src/module/components/ngx-auth-firebaseui-avatar/ngx-auth-firebaseui-avatar.component.html

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
<div fxLayout="column" style="padding-left: 10px; padding-right: 10px">
1919
<strong mat-card-title>{{user?.displayName}}</strong>
2020
<em mat-card-subtitle style="font-style: italic">{{user?.email}}</em>
21+
</div>
22+
</div>
2123

22-
<button mat-raised-button color="primary" (click)="openProfile()">Profile</button>
23-
<!--<a [routerLink]="['/profile']" [queryParams]="{id:user?._id}" mat-raised-button color="primary">Profile</a>-->
24+
<div fxLayout="column" fxFlex="100">
25+
<div *ngFor="let menuItem of links">
26+
<button mat-menu-item (click)="menuItem.callback">{{menuItem.text}}</button>
2427
</div>
28+
<button mat-raised-button fxLayoutAlign="center" color="primary" (click)="openProfile()">Profile
29+
</button>
30+
<button *ngIf="canLogout" mat-raised-button fxLayoutAlign="center" color="warn" (click)="signOut()">Sign Out
31+
</button>
2532
</div>
26-
<!--<button fxLayoutAlign="center center" mat-menu-item (click)="onPower()">-->
27-
<!--<mat-icon>power_settings_new</mat-icon>-->
28-
<!--{{isLoggedIn? ('APP.UI.BUTTON.LOGOUT' | translate) : ('APP.UI.BUTTON.LOGIN' | translate) }}-->
29-
<!--</button>-->
3033
</mat-menu>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.mat-raised-button {
2+
margin: 0.2rem 1rem;
3+
}

src/module/components/ngx-auth-firebaseui-avatar/ngx-auth-firebaseui-avatar.component.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
1-
import {Component, OnInit} from '@angular/core';
1+
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
22
import {AngularFireAuth} from '@angular/fire/auth';
33
import {User} from 'firebase';
44
import {Observable} from 'rxjs';
55
import {MatDialog} from '@angular/material';
66
import {UserComponent} from '../../..';
77

8+
export interface LinkMenuItem {
9+
text: string;
10+
icon?: string;
11+
callback?: Function;
12+
}
13+
814
@Component({
915
selector: 'ngx-auth-firebaseui-avatar',
1016
templateUrl: './ngx-auth-firebaseui-avatar.component.html',
1117
styleUrls: ['./ngx-auth-firebaseui-avatar.component.scss']
1218
})
1319
export class NgxAuthFirebaseuiAvatarComponent implements OnInit {
1420

21+
@Input()
22+
canLogout = true;
23+
24+
@Input()
25+
links: LinkMenuItem[];
26+
27+
@Output()
28+
onSignOut: EventEmitter<void> = new EventEmitter();
29+
1530
user: User;
1631
user$: Observable<User | null>;
1732
displayNameInitials: string;
@@ -41,4 +56,15 @@ export class NgxAuthFirebaseuiAvatarComponent implements OnInit {
4156
openProfile() {
4257
this.dialog.open(UserComponent);
4358
}
59+
60+
async signOut() {
61+
try {
62+
await this.afa.auth.signOut();
63+
// Sign-out successful.
64+
this.onSignOut.emit();
65+
} catch (e) {
66+
// An error happened.
67+
console.error('An error happened while signing out!', e);
68+
}
69+
}
4470
}

0 commit comments

Comments
 (0)