Skip to content

Instantly share code, notes, and snippets.

@blogcacanid
Created November 9, 2020 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blogcacanid/207a442002c24003d0ef347d4a02c551 to your computer and use it in GitHub Desktop.
Save blogcacanid/207a442002c24003d0ef347d4a02c551 to your computer and use it in GitHub Desktop.
app.component.ts Authentication JWT Angular 9 Lumen 7
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