Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const auth0Config = {
- clientID : {MYCLIENTID},
- clientId : {MYCLIENTID},
- domain : {MYAPPDOMAIN},
- callbackURL : location.href,
- packageIdentifier : {MYIONICPACKAGENAME}
- };
- login(){
- const client = new Auth0Cordova(auth0Config);
- const options = {
- scope: 'openid profile offline_access'
- };
- client.authorize(options, (err, authResult) => {
- if(err){
- alert(JSON.stringify(err));
- throw err; //The error occurs around here
- }
- this.setIdToken(authResult.idToken);
- this.setAccessToken(authResult.accessToken);
- const expiresAt = JSON.stringify((authResult.expiresIn * 1000) + new Date().getTime());
- this.setStorageVariable('expires_at', expiresAt);
- this.auth0.client.userInfo(this.access_token, (err, profile) => {
- if(err) {
- throw err;
- }
- profile.user_metadata = profile.user_metadata || {};
- this.setStorageVariable('profile', JSON.stringify(profile));
- this.zone.run(() => {
- this.user = profile;
- this.logged_in = true;
- });
- });
- });
- import { Component } from '@angular/core';
- import { NavController } from 'ionic-angular';
- import {TabHomePage} from '../tab-home/tab-home';
- import { UserServiceProvider } from '../../providers/user-service/user-service';
- import { RegistrationPage } from '../registration/registration';
- @Component({
- selector: 'page-home',
- templateUrl: 'home.html'
- })
- export class HomePage {
- email : string;
- password : string;
- constructor(public navCtrl: NavController, public _usp : UserServiceProvider) {
- }
- Login(){
- this._usp.login();
- }
- Go(){
- this.navCtrl.push(TabHomePage);
- }
- Logout(){
- this._usp.logout();
- }
- }
- <ion-content padding>
- <div text-center class="bottomize">
- <h1>MyApp</h1>
- <div *ngIf="!_usp.logged_in; else otherblock">
- <button ion-button (click)="Login()">Get Started</button>
- </div>
- <ng-template #otherblock>
- <button ion-button (click)="Go()">Go</button>
- <button ion-button (click)="Logout()">Log Out</button>
- </ng-template>
- </div>
- </ion-content>
Add Comment
Please, Sign In to add comment