Created
November 9, 2020 22:05
-
-
Save blogcacanid/207a442002c24003d0ef347d4a02c551 to your computer and use it in GitHub Desktop.
app.component.ts Authentication JWT Angular 9 Lumen 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
import { TokenStorageService } from './_services/token-storage.service'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.css'] | |
}) | |
export class AppComponent { | |
title = 'ang9-auth-jwt-lumen7'; | |
isLoggedIn = false; | |
username: string; | |
constructor(private tokenStorageService: TokenStorageService) { } | |
ngOnInit(): void { | |
this.isLoggedIn = !!this.tokenStorageService.getToken(); | |
if (this.isLoggedIn) { | |
const user = this.tokenStorageService.getUser(); | |
this.username = user.username; | |
} | |
} | |
logout(): void { | |
this.tokenStorageService.signOut(); | |
window.location.reload(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment