Skip to content
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
6 changes: 6 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"predeploy": ["node scripts/build.mjs"],
"site": "sentinel-b4194",
"ignore": ["firebase/**", "**/.git/**", "**/node_modules/**", "**/*.exe", "**/*.deb", "**/*.AppImage", "**/*.dmg"],
"redirects": [
{ "source": "/legal/terms-of-service.html", "destination": "/terms", "type": 301 }
],
"rewrites": [
{ "source": "/api/chat", "function": { "functionId": "chat", "region": "us-central1" } },
{ "source": "/version", "destination": "/version.txt" },
Expand Down Expand Up @@ -89,6 +92,9 @@
"predeploy": ["node scripts/build.mjs"],
"site": "sentinel-b4194-6173e",
"ignore": ["firebase/**", "**/.git/**", "**/node_modules/**", "**/*.exe", "**/*.deb", "**/*.AppImage", "**/*.dmg"],
"redirects": [
{ "source": "/legal/terms-of-service.html", "destination": "/terms", "type": 301 }
],
"rewrites": [
{ "source": "/api/chat", "function": { "functionId": "chat", "region": "us-central1" } },
{ "source": "/version", "destination": "/version.txt" },
Expand Down
92 changes: 92 additions & 0 deletions public/js/account-delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Self-service account deletion (Deck Settings > Data, and the older settings page). The
// Worker's POST /api/account/delete removes every server record and then the sign-in
// (worker/account-delete.js); this side confirms, re-checks the sign-in when it is older
// than 5 minutes, and clears this account's data from the browser afterwards.
import { auth, googleProvider, githubProvider } from "/js/firebase.js?v=20261021a";
import { reauthenticateWithPopup, reauthenticateWithCredential, EmailAuthProvider, signOut } from "https://www.gstatic.com/firebasejs/12.17.0/firebase-auth.js";

const proxyBase = () => { try { return String(window.DARKNODE_PROXY_URL || "").replace(/\/api\/chat$/, ""); } catch (_) { return ""; } };
const modal = (o) => (typeof window.dnModal === "function" ? window.dnModal(o) : Promise.resolve(null));

async function callDelete(user, fresh) {
const r = await fetch(proxyBase() + "/api/account/delete", {
method: "POST",
headers: { Authorization: "Bearer " + (await user.getIdToken(fresh)), "Content-Type": "application/json" },
body: JSON.stringify({ confirm: "DELETE" }),
});
let body = {}; try { body = await r.json(); } catch (_) {}
return { ok: r.ok, status: r.status, body };
}

// Sign in again with the account's own method. -> true when it worked.
async function reauth(user) {
const ids = (user.providerData || []).map((p) => p.providerId);
try {
if (ids.includes("google.com")) { await reauthenticateWithPopup(user, googleProvider); return true; }
if (ids.includes("github.com")) { await reauthenticateWithPopup(user, githubProvider); return true; }
if (ids.includes("password") && user.email) {
const v = await modal({ title: "Confirm it's you", desc: "Enter the password for " + user.email + ".", fields: [{ inputType: "password", placeholder: "Password" }], submitText: "Continue" });
if (!v || !v[0]) return false;
await reauthenticateWithCredential(user, EmailAuthProvider.credential(user.email, v[0]));
return true;
}
} catch (_) {}
return false;
}

// Remove this account's data from this browser only: keys named with its uid, its saved
// API keys, and its local security-graph snapshots. Other accounts on a shared browser keep theirs.
async function clearLocal(uid) {
try { if (window.dnKeys && window.dnKeys.clearForUid) window.dnKeys.clearForUid(uid); } catch (_) {}
try {
const rm = [];
for (let i = 0; i < localStorage.length; i++) { const k = localStorage.key(i); if (k && k.includes(uid)) rm.push(k); }
rm.forEach((k) => localStorage.removeItem(k));
localStorage.removeItem("dn_active_ws");
} catch (_) {}
try {
await new Promise((resolve) => {
const req = indexedDB.open("dn-secgraph", 1);
req.onerror = req.onblocked = () => resolve();
req.onupgradeneeded = () => { try { req.result.createObjectStore("snap"); } catch (_) {} };
req.onsuccess = () => {
try {
const db = req.result, tx = db.transaction("snap", "readwrite"), st = tx.objectStore("snap");
const kr = st.getAllKeys();
kr.onsuccess = () => { (kr.result || []).filter((k) => String(k).includes(uid)).forEach((k) => st.delete(k)); };
tx.oncomplete = tx.onerror = tx.onabort = () => { db.close(); resolve(); };
} catch (_) { resolve(); }
};
});
} catch (_) {}
}

export async function deleteAccount({ toast = () => {} } = {}) {
const user = auth.currentUser;
if (!user) { toast("Sign in first.", "error"); return false; }
if (!proxyBase()) { toast("Account deletion needs the cloud proxy, which this build has not configured.", "error"); return false; }
const v = await modal({
title: "Delete your Darknode account?",
desc: "This permanently deletes the account " + (user.email || "") + " and everything stored with it: your security graph, monitors and domain watch, API keys, settings and notifications, and any team workspace you hold alone. Team workspaces you joined keep their own data. This cannot be undone. Type DELETE to confirm.",
fields: [{ placeholder: "DELETE" }],
submitText: "Delete account", danger: true,
});
if (!v) return false;
if (String(v[0] || "").trim() !== "DELETE") { toast("Type DELETE in capitals to confirm.", "error"); return false; }
let r;
try {
r = await callDelete(user, false);
if (r.status === 401 && r.body.reauth) {
if (!(await reauth(user))) { toast("Couldn't confirm it's you. Sign out, sign in again, then delete within 5 minutes.", "error"); return false; }
r = await callDelete(user, true);
}
} catch (_) { toast("Couldn't reach Darknode. Check your connection and try again.", "error"); return false; }
if (r.status === 409) { await modal({ title: "Remove the other members first", desc: r.body.error, submitText: "OK", cancelText: "Close" }); return false; }
if (!r.ok) { toast(r.body.error || "Deletion failed (HTTP " + r.status + "). Try again.", "error"); return false; }
const uid = user.uid;
await clearLocal(uid);
await modal({ title: "Your account is deleted", desc: "Your Darknode account and its data are gone. You can sign up again at any time with a new account.", submitText: "OK", cancelText: "Close" });
try { await signOut(auth); } catch (_) {}
try { location.replace("/"); } catch (_) {}
return true;
}
16 changes: 10 additions & 6 deletions public/js/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,13 @@ function renderVerify(user) {
<button class="btn" id="reload">I've verified — reload</button>
<button class="btn ghost" id="resend">Resend email</button>
<p id="err" class="auth-err"></p>
<p class="muted" style="margin-top:14px;font-size:.85rem">Wrong address, or don't want the account? <a href="#" id="delacct">Delete this account</a></p>
</section>`;
document.getElementById("delacct").onclick = async (e) => {
e.preventDefault();
try { const m = await import("/js/account-delete.js?v=1"); await m.deleteAccount({ toast: showToast }); }
catch (_) { showToast("Couldn't load account deletion. Reload and try again.", "error"); }
};
document.getElementById("reload").onclick = async () => {
await reload(user);
if (user.emailVerified) location.reload();
Expand Down Expand Up @@ -1540,8 +1546,8 @@ claude mcp add darknode -- node ~/darknode-cli/darknode.js mcp</code></pre>
<button class="btn ghost" id="data-clear" type="button" style="flex:none">Clear data</button>
</div>
${isGuest ? "" : `<div class="set-row" style="align-items:center;gap:16px">
<span style="display:flex;flex-direction:column;gap:3px"><b>Delete my account</b><span class="muted" style="font-size:.76rem">Request permanent deletion of your Darknode account and its records. We confirm by email.</span></span>
<button class="btn danger" id="data-delete" type="button" style="flex:none">Request deletion</button>
<span style="display:flex;flex-direction:column;gap:3px"><b>Delete my account</b><span class="muted" style="font-size:.76rem">Permanently delete your Darknode account and everything stored with it. This cannot be undone.</span></span>
<button class="btn danger" id="data-delete" type="button" style="flex:none">Delete account</button>
</div>`}
</div>
<p class="muted" style="font-size:.72rem;margin-top:14px">Questions about your data? Email <a href="mailto:contact@darknode.ai" style="color:var(--acc)">contact@darknode.ai</a>.</p>`,
Expand Down Expand Up @@ -1649,10 +1655,8 @@ claude mcp add darknode -- node ~/darknode-cli/darknode.js mcp</code></pre>
};
const dataDelete = main.querySelector("#data-delete");
if (dataDelete) dataDelete.onclick = async () => {
const ok = window.dnConfirm ? await window.dnConfirm("Request account deletion?", "We'll permanently delete your Darknode account and its records, then confirm by email to " + (user.email || "your address") + ".", { submitText: "Request deletion", danger: true }) : true;
if (!ok) return;
try { await setDoc(doc(db, "deletionRequests", user.uid), { uid: user.uid, email: user.email || "", requestedAt: serverTimestamp() }, { merge: true }); showToast("Deletion request received. We'll confirm by email.", "success"); }
catch (e) { showToast("Could not file the request: " + ((e && e.message) || "try emailing contact@darknode.ai"), "error"); }
try { const m = await import("/js/account-delete.js?v=1"); await m.deleteAccount({ toast: showToast }); }
catch (_) { showToast("Couldn't load account deletion. Reload and try again.", "error"); }
};
// MCP + code-block copy buttons
const mcpCopy = main.querySelector("#dn-mcp-copy2");
Expand Down
11 changes: 11 additions & 0 deletions public/js/deck-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -4560,6 +4560,10 @@ export function renderDeck(host, opts) {
<div class="m"><div class="t">Reset local Deck state</div><div class="s">Clears connections, pins, notes and layout in this browser. Does not touch your account or the security graph.</div></div>
<button class="dk-settog" id="dkSetReset" style="border-color:rgba(200,50,50,.4);color:#b4332e">Reset</button>
</div>
${noAccount ? "" : `<div class="dk-setrow">
<div class="m"><div class="t">Delete account</div><div class="s">Permanently deletes your account and everything stored with it: security graph, monitors, API keys, settings, and team workspaces you hold alone. Export first if you want a copy.</div></div>
<button class="dk-settog" id="dkSetDelAcct" style="border-color:rgba(200,50,50,.4);color:#b4332e">Delete</button>
</div>`}
</div>

${opts.isOwner ? `<div class="dk-ovp">
Expand Down Expand Up @@ -4633,6 +4637,13 @@ export function renderDeck(host, opts) {
toast("Local Deck state reset — reloading");
setTimeout(() => { try { location.reload(); } catch (_) {} }, 600);
};
const delAcct = el.querySelector("#dkSetDelAcct");
if (delAcct) delAcct.onclick = async () => {
delAcct.disabled = true;
try { const m = await import("/js/account-delete.js?v=1"); await m.deleteAccount({ toast }); }
catch (_) { toast("Couldn't load account deletion. Reload and try again.", "error"); }
finally { delAcct.disabled = false; }
};
const admBtn = el.querySelector("#dkSetAdmin");
if (admBtn) admBtn.onclick = () => openTool("admin", "Admin");
fqMod().then((m) => m.renderSlaSettings(el.querySelector(".dk-setgrid"), fqCtx()), () => {});
Expand Down
2 changes: 1 addition & 1 deletion public/js/docs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions public/js/legal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading