Browse Source

bugfix: failing to create twit client when not logged in

Carsten Porth 5 years ago
parent
commit
6a32fc96b6

+ 4 - 5
app/src/pages/home/home.ts

@@ -80,8 +80,8 @@ export class HomePage {
 
   get oldestPublicTweet() {
     if (this.publicTweets.length > 0) {
-      return this.publicTweets.reduce(
-        (acc, cur) => (acc.id < cur.id ? acc : cur)
+      return this.publicTweets.reduce((acc, cur) =>
+        acc.id < cur.id ? acc : cur
       );
     } else {
       return undefined;
@@ -90,9 +90,8 @@ export class HomePage {
 
   get oldestPrivateTweet() {
     if (this.privateTweets.length > 0) {
-      return this.privateTweets.reduce(
-        (acc, cur) =>
-          new Date(acc.created_at) < new Date(cur.created_at) ? acc : cur
+      return this.privateTweets.reduce((acc, cur) =>
+        new Date(acc.created_at) < new Date(cur.created_at) ? acc : cur
       );
     } else {
       return undefined;

+ 1 - 2
app/src/pages/login/login.ts

@@ -8,7 +8,6 @@ import {
   ModalController
 } from "ionic-angular";
 import { AuthProvider } from "../../providers/auth/auth";
-import { HomePage } from "../home/home";
 import { AboutPage } from "../about/about";
 
 @IonicPage()
@@ -40,7 +39,7 @@ export class LoginPage {
 
     this.authProvider
       .login()
-      .then(() => this.navCtrl.setRoot(HomePage))
+      .then(() => window.location.reload())
       .catch(err => this.alertCtrl.create(alertText).present());
   }
 

+ 14 - 7
app/src/providers/twitter-api/twitter-api.ts

@@ -14,13 +14,20 @@ export class TwitterApiProvider {
   private async initApi() {
     const access_token_key = await this.storage.get("accessTokenKey");
     const access_token_secret = await this.storage.get("accessTokenSecret");
-    this.client = new Twit({
-      consumer_key: "UxZkbKotkr8Uc6seupnaZ1kDE",
-      consumer_secret: "fEAas8iugR60FOEXsFG0iajq6oyfIIXRBVMlTgWxBd1stWIKHq",
-      access_token: access_token_key,
-      access_token_secret: access_token_secret,
-      timeout_ms: 60 * 1000 // optional HTTP request timeout to apply to all requests.
-    });
+    if (access_token_key && access_token_secret) {
+      this.client = new Twit({
+        consumer_key: "UxZkbKotkr8Uc6seupnaZ1kDE",
+        consumer_secret: "fEAas8iugR60FOEXsFG0iajq6oyfIIXRBVMlTgWxBd1stWIKHq",
+        access_token: access_token_key,
+        access_token_secret: access_token_secret,
+        timeout_ms: 60 * 1000 // optional HTTP request timeout to apply to all requests.
+      });
+    } else {
+      console.error(
+        "Access Token Key and Secret not set. Creating Twit-client not possible."
+      );
+      console.info("This error can be ignored if no user is logged in.");
+    }
   }
 
   public async fetchHomeFeed(maxId?) {