Skip to content

Instantly share code, notes, and snippets.

@supunlakmal

supunlakmal/auth Secret

Created April 9, 2019 01:58
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 supunlakmal/ed04fc1da234338b35d841059d45eaab to your computer and use it in GitHub Desktop.
Save supunlakmal/ed04fc1da234338b35d841059d45eaab to your computer and use it in GitHub Desktop.
import {
Component,
OnInit
} from '@angular/core';
import {
Router,
RouterModule,
Routes
} from '@angular/router';
import {
HttpClient,
HttpHeaders
} from '@angular/common/http';
export class SystemComponent implements OnInit {
constructor( private http: HttpClient, private router: Router) {}
ngOnInit() {
const self = this;
const sendData = {};
sendData['id'] = sessionStorage.getItem('id');
console.log(JSON.stringify(sendData));
const headers = new HttpHeaders()
.set('Content-Type', 'application/json')
.set('token', sessionStorage.getItem('auth') ? sessionStorage.getItem('auth') : 'thismyPc');
this.http.post('http://thismypc.com:5000/auth',
JSON.stringify(sendData), {
headers
})
.subscribe(
(val: any) => {},
response => {
// if offline
this.router.navigate(['/login']);
},
() => {
console.log('The POST observable is now completed.');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment