npmtest-node-red-contrib-firebase (v0.0.1)

Code coverage report for node-npmtest-node-red-contrib-firebase/node_modules/node-red-contrib-firebase/firebase/firebase_auth.js

Statements: 7.14% (2 / 28)      Branches: 0% (0 / 8)      Functions: 0% (0 / 6)      Lines: 7.14% (2 / 28)      Ignored: none     

All files » node-npmtest-node-red-contrib-firebase/node_modules/node-red-contrib-firebase/firebase/ » firebase_auth.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 591     1                                                                                                              
module.exports = function(RED) {
    'use strict';
 
    function FirebaseAuth(n) {
        RED.nodes.createNode(this,n);
 
        this.config = RED.nodes.getNode(n.firebaseconfig);
        this.name = n.name;
        this.ready = false;
 
        // Check credentials
        if (!this.config) {
            this.status({fill:"red", shape:"ring", text:"invalid credentials"})
            this.error('You need to setup Firebase credentials!');
            return
        }
 
        this.fbAuthorized = function(authData){
          // this.log("authorized")
          this.status({fill:"green", shape:"dot", text:"ready"})
          this.send({payload: authData})
        }.bind(this)
 
        this.fbUnauthorized = function(){
          // this.log("unauthorized")
          this.status({fill:"red", shape:"dot", text:"unauthorized"})
          this.send({payload: null})
        }.bind(this)
 
 
        //Register Handlers
 
        this.config.fbConnection.on("authorized", this.fbAuthorized)
        this.config.fbConnection.on("unauthorized", this.fbUnauthorized)
 
        if(this.config.fbConnection.authData)
            this.send({payload: this.config.fbConnection.authData})
 
 
 
          this.on('close', function() {
            //Cancel modify request to firebase??
          });
 
    }
    RED.nodes.registerType("firebase auth", FirebaseAuth);
 
    RED.httpAdmin.post("/firebase/:id/auth", RED.auth.needsPermission("firebase.write"), function(req,res) {
            var node = RED.nodes.getNode(req.params.id);
            if (node !== null && typeof node !== "undefined" ) {
                node.send({payload: node.config.fbConnection.authData});
                res.sendStatus(200)
            } else {
                res.send(404);
            }
        });
};