diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 7791ef2..03b8584 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -21,6 +21,8 @@ export class MyApp { pages: Array<{title: string, component: any, params: Object}>; + scope: Array = ['basic','stream','write_post','files']; + constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, private storage: Storage, private device: Device) { this.initializeApp(); @@ -67,11 +69,22 @@ export class MyApp { this.storage.get('token').then((val) => { if (val.length > 1) { pnut.token = val; - this.nav.setRoot(StreamPage, {stream: timeline}); + + this.storage.get('scope').then((sval) => { + if (JSON.stringify(sval) !== JSON.stringify(this.scope)) { + this.nav.setRoot(LoginPage, {'scope': this.scope}); + } else { + this.nav.setRoot(StreamPage, {stream: timeline}); + } + // this.nav.setRoot(StreamPage, {stream: timeline}); + }).catch(err => { + this.nav.setRoot(LoginPage, {'scope': this.scope}); + }); + // this.nav.setRoot(StreamPage, {stream: timeline}); } }).catch(err => { console.log('ERROR: ' + err); - this.nav.setRoot(LoginPage); + this.nav.setRoot(LoginPage, {'scope': this.scope}); }); } @@ -81,7 +94,7 @@ export class MyApp { if (page.title === 'Logout') { // this.storage.remove('token'); this.storage.clear(); - this.nav.setRoot(LoginPage); + this.nav.setRoot(LoginPage, {'scope': this.scope}); } else if (page.title === 'Settings') { this.nav.push(page.component, page.params); } else { diff --git a/src/pages/login/login.ts b/src/pages/login/login.ts index 8af4c39..0bebda9 100644 --- a/src/pages/login/login.ts +++ b/src/pages/login/login.ts @@ -26,28 +26,29 @@ export class LoginPage { private oob: boolean = false; public showToken: boolean = false; private token: string; + private scope: Array = []; constructor(public navCtrl: NavController, public navParams: NavParams, private storage: Storage, private device: Device) { - let scope = ['basic','stream','write_post','files']; + this.scope = navParams.data.scope; if (this.device.platform === "Android" || this.device.platform === "amazon-fireos") { this.oauth = new OauthCordova(); this.pnutProvider = new PnutAuth({ - appScope: scope, + appScope: this.scope, redirectUri: 'http://localhost/callback' }); } else if (this.device.platform === "blackberry10") { this.oauth = new OauthBrowser(); this.pnutProvider = new PnutAuth({ - appScope: scope, + appScope: this.scope, redirectUri: 'https://zoidberg.monkeystew.net/' }); } else { this.oauth = new OauthBrowser(); this.pnutProvider = new PnutAuth({ - appScope: scope, + appScope: this.scope, redirectUri: 'urn:ietf:wg:oauth:2.0:oob' }); this.oob = true; @@ -59,6 +60,7 @@ export class LoginPage { this.oauth.logInVia(this.pnutProvider).then(success => { console.log('RESULT: ' + JSON.stringify(success)); this.storage.set('token', success['access_token']); + this.storage.set('scope', this.scope); pnut.token = success['access_token']; this.navCtrl.setRoot(StreamPage, {stream: 'personal'}); }, error => { @@ -70,6 +72,7 @@ export class LoginPage { } saveToken() { + this.storage.set('scope', this.scope); this.storage.set('token', this.token); pnut.token = this.token; this.navCtrl.setRoot(StreamPage, {stream: 'personal'}); diff --git a/src/pages/stream/stream.ts b/src/pages/stream/stream.ts index 595b9c6..f9b73e4 100644 --- a/src/pages/stream/stream.ts +++ b/src/pages/stream/stream.ts @@ -167,8 +167,6 @@ export class StreamPage { count: 40 }; this.fetcher(params).then(res => { - console.log('-fetch success-'); - console.log(JSON.stringify(res)); if (res.meta.code === 401) { this.storage.clear(); this.navCtrl.setRoot(LoginPage);