diff --git a/resources/drag-and-drop.js b/resources/drag-and-drop.js
index d2c0446..f7e07c3 100644
--- a/resources/drag-and-drop.js
+++ b/resources/drag-and-drop.js
@@ -105,20 +105,35 @@ const FirebaseConfigDropArea = (function () {
}
#parseAndUpdateInputs(content) {
+ // Remove previous class - default style
+ this.privateKeyFile.removeClass("json-error").removeClass("json-properties-error");
+
try {
const data = JSON.parse(content);
+ const clientEmail = data["clientEmail"] || data["client_email"] || "";
+ const privateKey = data["privateKey"] || data["private_key"] || "";
+
+ if (!clientEmail || !privateKey) {
+ RED.notify(`JSON file: '${privateKey ? "Client Email" : "Private Key"}' property missing.`, "error");
+ this.privateKeyFile
+ .addClass("json-properties-error")
+ .html("
Please ensure your JSON file contains the clientEmail
and privateKey
properties.
");
+ return;
+ }
$("#node-config-input-clientEmail")
- .data("data", data["clientEmail"] || data["client_email"])
+ .data("data", clientEmail)
.val("__PWRD__");
$("#node-config-input-privateKey")
- .data("data", (data["privateKey"] || data["private_key"] || "").trim())
+ .data("data", privateKey.trim())
.val("__PWRD__");
- $("#node-config-input-projectId").val(data["projectId"] || data["project_id"])
+ $("#node-config-input-projectId")
+ .val(data["projectId"] || data["project_id"])
.trigger("change"); // No need to trigger everything
+
this.privateKeyFile.html("The file has been loaded.");
} catch (error) {
- this.privateKeyFile.html("An error has occurred :(");
+ this.privateKeyFile.addClass("json-error").html("An error has occurred :(");
alert(error.message ?? String(error));
}
}
diff --git a/resources/styles.css b/resources/styles.css
index 1b856f2..4537d23 100644
--- a/resources/styles.css
+++ b/resources/styles.css
@@ -41,11 +41,12 @@
#json-drop-target {
cursor: pointer;
+ display: grid;
+ place-items: center;
margin: auto;
width: 100%;
height: 150px;
text-align: center;
- line-height: 150px;
background-color: lightgrey;
color: darkgray;
border-color: darkgray;
@@ -57,6 +58,15 @@
box-shadow: 11px 10px 17px -12px rgba(0, 0, 0, 0.75);
}
+#json-drop-target.json-error {
+ color: var(--red-ui-form-input-border-error-color) !important;
+}
+
+#json-drop-target.json-properties-error {
+ color: var(--red-ui-form-input-border-error-color) !important;
+ font-size: var(--red-ui-primary-font-size);
+}
+
#file-drop-target {
position: absolute;
top: 0;
diff --git a/src/lib/nodes/firebase-client.ts b/src/lib/nodes/firebase-client.ts
index 8a07161..bd9a8d9 100644
--- a/src/lib/nodes/firebase-client.ts
+++ b/src/lib/nodes/firebase-client.ts
@@ -204,26 +204,26 @@ export class FirebaseClient {
if (Object.keys(content).length === 0) {
const { credentials } = this.node;
+
+ // Get the projectId from URL (v < 0.6)
const projectId = credentials.url
?.split("https://")
.pop()
?.split(/-default-rtdb\.((asia-southeast1|europe-west1)\.firebasedatabase\.app|firebaseio\.com)(\/)?$/)[0];
- // For line breaks issue
+ // For line breaks issue (v < 0.6)
const privateKey = JSON.stringify(credentials.privateKey)
?.replace(/\\\\n/gm, "\n")
.replaceAll('"', "")
.replaceAll("\\", "");
- cred.clientEmail = credentials.clientEmail;
-
// The introduction of 'projectId' in the credentials also introduces the change from 'val()' to 'data("data")'
// which no longer needs to be stringify to solve the line breaks issue
- cred.privateKey = privateKey.match("\n") === null ? credentials.privateKey : privateKey;
+ cred.privateKey = privateKey?.match("\n") === null ? credentials.privateKey : privateKey;
cred.projectId = credentials.projectId || projectId;
-
- // For json input (deprecated)
+ cred.clientEmail = credentials.clientEmail;
} else {
+ // For json input (deprecated)
cred.clientEmail = content.clientEmail || content.client_email;
cred.privateKey = content.privateKey || content.private_key;
cred.projectId = content.projectId || content.project_id;