Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular-universal | firebase-admin | code: 'app/invalid-credential' |socket hang up on

import * as admin from 'firebase-admin';
var serviceAccount = require('./keys/keyfile.json');
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://test.firebaseio.com"
});

var registrationToken = "--some-key--";

var payload = {
  notification: {
    title: "$GOOG up 1.43% on the day",
    body: "$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day."
  },
  data: {
    stock: "GOOG",
    open: "829.62",
    close: "635.67"
  }
};


function panelMessage(){
admin.messaging().sendToDevice(registrationToken, payload)
  .then(function(response) {
    // See the MessagingDevicesResponse reference documentation for
    // the contents of response.
    console.log("Successfully sent message:", response);
  })
  .catch(function(error) {
    // console.log(serviceAccount);
    var date = new Date();
    console.log(date.toString());
    console.log("Error sending message:", error);
  });
}

I run this code through node and it work but when i add it in angular-universal

server.ts

file.. it give the following error..

Error sending message: { Error: Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "socket hang up". at FirebaseAppError.Error (native) at FirebaseAppError.FirebaseError [as constructor] (D:\angular2MH\firebase - panel\panel\node_modules\firebase-admin\lib\utils\error.js:39:28) at new FirebaseAppError (D:\angular2MH\firebase - panel\panel\node_modules\firebase-admin\lib\utils\error.js:84:23) at D:\angular2MH\firebase - panel\panel\node_modules\firebase-admin\lib\firebase-app.js:119:23 at ZoneDelegate.invoke (D:\angular2MH\firebase - panel\panel\node_modules\zone.js\dist\zone-node.js:232:26) at Zone.run (D:\angular2MH\firebase - panel\panel\node_modules\zone.js\dist\zone-node.js:114:43) at D:\angular2MH\firebase - panel\panel\node_modules\zone.js\dist\zone-node.js:502:57 at ZoneDelegate.invokeTask (D:\angular2MH\firebase - panel\panel\node_modules\zone.js\dist\zone-node.js:265:35) at Zone.runTask (D:\angular2MH\firebase - panel\panel\node_modules\zone.js\dist\zone-node.js:154:47) at drainMicroTaskQueue (D:\angular2MH\firebase - panel\panel\node_modules\zone.js\dist\zone-node.js:401:35)
errorInfo: { code: 'app/invalid-credential', message: 'Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "socket hang up".' } }

I checked the time (read at many place that could be the issue) and they are all synced.. Can anyone help me out with the issue? I'm using this repository repository

like image 945
Himanshu Bansal Avatar asked Aug 09 '17 07:08

Himanshu Bansal


1 Answers

From Firebase-Support, Angular-Universal is not a library that we officially support. so no OAuth can be provided.

To deal with the issue, I made another server for firebase and made api calls from universal server. Its working fine now.

like image 81
Himanshu Bansal Avatar answered Sep 20 '22 14:09

Himanshu Bansal