Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions nodecg-io-core/dashboard/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const inputPassword = document.getElementById("inputPassword") as HTMLInputEleme
const divAuth = document.getElementById("divAuth");
const divMain = document.getElementById("divMain");
const spanPasswordNotice = document.getElementById("spanPasswordNotice") as HTMLSpanElement;
const pFirstStartup = document.getElementById("pFirstStartup");

// Add key listener to password input
inputPassword?.addEventListener("keyup", function (event) {
Expand All @@ -25,12 +26,14 @@ nodecg.socket.on("connect", () => {
loadFramework();
} else {
updateLoadedStatus();
updateFirstStartupLabel();
}
});

document.addEventListener("DOMContentLoaded", () => {
// Render loaded status for initial load
updateLoadedStatus();
updateFirstStartupLabel();
});

export async function isLoaded(): Promise<boolean> {
Expand Down Expand Up @@ -71,3 +74,12 @@ export async function loadFramework(): Promise<void> {

updateLoadedStatus();
}

async function updateFirstStartupLabel(): Promise<void> {
const isFirstStartup: boolean = await nodecg.sendMessage("isFirstStartup");
if (isFirstStartup) {
pFirstStartup?.classList.add("hidden");
} else {
pFirstStartup?.classList.remove("hidden");
}
}
4 changes: 4 additions & 0 deletions nodecg-io-core/dashboard/panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<p>Current status: <span id="spanLoaded">Unknown</span></p>

<div id="divAuth">
<p id="pFirstStartup" class="hidden">
This seems to be your first startup of nodecg-io. Please choose a password which will be used to encrypt
all your credentials.
</p>
<p>Login:</p>
<div class="margins">
<label for="inputPassword">Password: </label>
Expand Down
6 changes: 6 additions & 0 deletions nodecg-io-core/extension/messageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ export class MessageManager {
ack?.(undefined, result);
}
});

this.nodecg.listenFor("isFirstStartup", (_msg: undefined, ack) => {
if (!ack?.handled) {
ack?.(undefined, this.persist.isFirstStartup());
}
});
}

authRequired<M extends PasswordMessage, V>(handler: ListenForCallback<M, V>): ListenForCallback<M, V> {
Expand Down
8 changes: 8 additions & 0 deletions nodecg-io-core/extension/persistenceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ export class PersistenceManager {
return this.password !== undefined;
}

/**
* Returns whether this is the first startup aka. whether any encrypted data has been saved.
* If this returns true {{@link load}} will accept any password and use it to encrypt the configuration.
*/
isFirstStartup(): boolean {
return this.encryptedData.value.cipherText !== undefined;
}

/**
* Decrypts and loads the locally stored configuration using the passed password.
* @param password the password of the encrypted config.
Expand Down