Skip to content

Commit

Permalink
Add cookies service to npm. Set token to cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
gbdrm committed Jul 25, 2016
1 parent e67a322 commit 8c7aadd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ClientApp/components/home/home.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import * as ng from '@angular/core';
import { ROUTER_DIRECTIVES } from '@angular/router';
import { Cookie } from 'ng2-cookies/ng2-cookies';
import { Http } from '@angular/http';

@ng.Component({
selector: 'home',
template: require('./home.html'),
directives: [...ROUTER_DIRECTIVES]
directives: [...ROUTER_DIRECTIVES],
})
export class Home {
constructor(private http: Http) { }

ngOnInit() {
let token = Cookie.get('playerToken');
if (!token) {
this.http.get('/home/registernewplayer').subscribe(result => {
token = result.text();
Cookie.set('playerToken', token);
});
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"aspnet-webpack": "^1.0.1",
"css": "^2.2.1",
"isomorphic-fetch": "^2.2.1",
"ng2-cookies": "^1.0.1",
"preboot": "^2.0.10",
"rxjs": "5.0.0-beta.6",
"webpack-externals-plugin": "^1.0.0",
Expand Down

0 comments on commit 8c7aadd

Please sign in to comment.