Guest User

Untitled

a guest
Mar 18th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. const auth0Config = {
  2. clientID : {MYCLIENTID},
  3. clientId : {MYCLIENTID},
  4. domain : {MYAPPDOMAIN},
  5. callbackURL : location.href,
  6. packageIdentifier : {MYIONICPACKAGENAME}
  7. };
  8.  
  9. login(){
  10. const client = new Auth0Cordova(auth0Config);
  11.  
  12. const options = {
  13. scope: 'openid profile offline_access'
  14. };
  15.  
  16. client.authorize(options, (err, authResult) => {
  17.  
  18. if(err){
  19. alert(JSON.stringify(err));
  20. throw err; //The error occurs around here
  21. }
  22.  
  23. this.setIdToken(authResult.idToken);
  24. this.setAccessToken(authResult.accessToken);
  25.  
  26. const expiresAt = JSON.stringify((authResult.expiresIn * 1000) + new Date().getTime());
  27. this.setStorageVariable('expires_at', expiresAt);
  28.  
  29. this.auth0.client.userInfo(this.access_token, (err, profile) => {
  30. if(err) {
  31. throw err;
  32. }
  33.  
  34. profile.user_metadata = profile.user_metadata || {};
  35. this.setStorageVariable('profile', JSON.stringify(profile));
  36. this.zone.run(() => {
  37. this.user = profile;
  38. this.logged_in = true;
  39. });
  40. });
  41. });
  42.  
  43. import { Component } from '@angular/core';
  44. import { NavController } from 'ionic-angular';
  45. import {TabHomePage} from '../tab-home/tab-home';
  46. import { UserServiceProvider } from '../../providers/user-service/user-service';
  47. import { RegistrationPage } from '../registration/registration';
  48.  
  49. @Component({
  50. selector: 'page-home',
  51. templateUrl: 'home.html'
  52. })
  53. export class HomePage {
  54.  
  55. email : string;
  56. password : string;
  57.  
  58. constructor(public navCtrl: NavController, public _usp : UserServiceProvider) {
  59.  
  60. }
  61.  
  62. Login(){
  63. this._usp.login();
  64. }
  65.  
  66. Go(){
  67. this.navCtrl.push(TabHomePage);
  68. }
  69.  
  70. Logout(){
  71. this._usp.logout();
  72. }
  73.  
  74. }
  75.  
  76. <ion-content padding>
  77.  
  78. <div text-center class="bottomize">
  79. <h1>MyApp</h1>
  80. <div *ngIf="!_usp.logged_in; else otherblock">
  81. <button ion-button (click)="Login()">Get Started</button>
  82. </div>
  83. <ng-template #otherblock>
  84. <button ion-button (click)="Go()">Go</button>
  85. <button ion-button (click)="Logout()">Log Out</button>
  86. </ng-template>
  87. </div>
  88. </ion-content>
Add Comment
Please, Sign In to add comment