-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.js
executable file
·54 lines (50 loc) · 1.48 KB
/
config.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
module.exports = function(RED) {
"use strict";
var firebase = require("firebase/app");
// Add the Firebase
require("firebase/auth");
require("firebase/database");
const firebaseConfig = {
apiKey: "AIzaSyBnbSCjJ9eQtAMl_CHRSJxelF5XG8UlLjU",
authDomain: "smartlife-air.firebaseapp.com",
databaseURL: "https://smartlife-air.firebaseio.com",
projectId: "smartlife-air",
storageBucket: "smartlife-air.appspot.com",
messagingSenderId: "121967033816",
appId: "1:121967033816:web:222bbc68de21111ac0c6ad",
measurementId: "G-YHBTVPG19R"
};
function loginNode(n) {
RED.nodes.createNode(this, n);
// Initialize Firebase
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
if (n.email && n.password) {
this.auth = firebase.auth();
this.db = firebase.database();
let retry = true;
const login = ()=>{
if(retry)
this.auth.signInWithEmailAndPassword(n.email, n.password).catch(error => {
// Handle Errors here.
console.log("Smartlife Air: Auth Error From Config Node")
console.log(error.message);
retry = true;
setTimeout(() => {
login();
}, 10000);
});
}
this.auth.onAuthStateChanged(function(user) {
if (user) {
retry = false;
} else {
retry = true;
login();
}
});
}
}
RED.nodes.registerType("smartlifeair-login", loginNode);
};