Created
April 26, 2016 15:40
-
-
Save pjlamb12/b99d47d235e13aa00b535d063ef20a87 to your computer and use it in GitHub Desktop.
NgZone After Auth0 Login
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 {Injectable, NgZone} from 'angular2/core'; | |
import {Http, Response, Headers} from 'angular2/http'; | |
import {Router} from 'angular2/router'; | |
import {tokenNotExpired} from 'angular2-jwt'; | |
import 'rxjs/add/operator/map'; | |
import {AppConfig} from '../services/config'; | |
declare var Auth0Lock: any; | |
@Injectable() | |
export class Session { | |
constructor(private _http:Http, private _config: AppConfig, private _router: Router, private _zone: NgZone) {} | |
lock = new Auth0Lock(this._config.getAuthClientId(), this._config.getAuthDomain()); | |
login() { | |
this.lock.show((error: string, profile: Object, id_token: string) => { | |
if (error) { | |
console.error(error); | |
} | |
localStorage.setItem('profile', JSON.stringify(profile)); | |
localStorage.setItem('id_token', id_token); | |
this._router.navigate(['Dashboard']); | |
var test = this.loggedIn(); | |
this._zone.run(() => {}); | |
}); | |
} | |
logout() { | |
localStorage.removeItem('profile'); | |
localStorage.removeItem('id_token'); | |
// redirect to home | |
this._router.navigate(['Home']); | |
} | |
loggedIn() { | |
return tokenNotExpired(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment