Skip to content

Commit 3fdd990

Browse files
committed
Angular Security course
1 parent 7224ff5 commit 3fdd990

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

server/get-user.route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ export function getUser(req:Request, res:Response) {
99

1010
const userInfo = req["user"];
1111

12-
const user = db.findUserById(userInfo.sub);
12+
if (userInfo) {
13+
14+
const user = db.findUserById(userInfo.sub);
1315

14-
if (user) {
1516
res.status(200).json({email:user.email, id:user.id, roles: user.roles});
1617
}
1718
else {

src/app/app.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<a routerLink="/lessons">Lessons</a>
1111
</li>
1212
<li>
13-
<a routerLink="/admin">ADMIN</a>
13+
<a routerLink="/admin">Admin</a>
1414
</li>
1515
<li *ngIf="isLoggedOut$ | async">
1616
<a routerLink="/signup">Sign Up</a>
@@ -30,6 +30,8 @@
3030
<h3>Angular Security MasterClass</h3>
3131
<img class="course-logo"
3232
src="https://s3-us-west-1.amazonaws.com/angular-university/course-images/angular-security-thumbnail.png">
33+
34+
<div *ngIf="(user$ | async) as user">User: {{user.email}}</div>
3335
</div>
3436

3537
<router-outlet></router-outlet>

src/app/app.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class AppComponent implements OnInit {
1212

1313
isLoggedIn$: Observable<boolean>;
1414
isLoggedOut$: Observable<boolean>;
15+
user$: Observable<User>;
1516

1617
constructor(private authService:AuthService) {
1718

@@ -20,6 +21,7 @@ export class AppComponent implements OnInit {
2021
ngOnInit() {
2122
this.isLoggedIn$ = this.authService.isLoggedIn$;
2223
this.isLoggedOut$ = this.authService.isLoggedOut$;
24+
this.user$ = this.authService.user$;
2325
}
2426

2527
logout() {

0 commit comments

Comments
 (0)