Skip to content

Instantly share code, notes, and snippets.

@avatsaev
Created February 9, 2017 17:38
Show Gist options
  • Save avatsaev/a6472d93859f8f1f7435fbec4e12071e to your computer and use it in GitHub Desktop.
Save avatsaev/a6472d93859f8f1f7435fbec4e12071e to your computer and use it in GitHub Desktop.
import { Component } from '@angular/core';
import {Angular2TokenService} from "angular2-token";
import {environment} from "../environments/environment";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.sass']
})
export class AppComponent {
title = 'app works!';
constructor(private authToken: Angular2TokenService){
this.authToken.init(environment.token_auth_config);
this.authToken.signIn({email: "user@example.com", password: "monkey67"}).subscribe(
res => {
console.log('auth response:', res);
console.log('auth response headers: ', res.headers.toJSON()); //log the response header to show the auth token
console.log('auth response body:', res.json()); //log the response body to show the user
},
err => {
console.error('auth error:', err);
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment