mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-10 23:01:10 +00:00
[upload] Auto-unlock storage in the upload modal for a kept-unlocked session (#51)
The upload modal only READ storage's unlock state (isUnlocked) on load/open/refresh
— it never auto-unlocked the way the profile Storage pane does. So after a refresh
with "keep unlocked" ticked, the upload modal still opened with storage Locked even
though the signer had been restored.
Add UploadModal.maybeAutoUnlockStorage(pubkey), called on load(), open(), and
refreshState(): if storage is locked but a decrypt-capable signer is already present
(e.g. a kept-unlocked nsec restored on refresh), unlock silently. Guarded two ways:
- only when the account ALREADY exists (new storageService.hasStoredAccount) so it
never auto-creates storage for magnet/URL-only uploaders, and
- only when the signer is already available, so it never triggers a fresh
permission prompt on modal open.
Tests: storageService.hasStoredAccount (false before setup, true after unlock,
never creates an account, survives lock). Lint + build green.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
cebd3dc1e7
commit
6bdf28fb30
3 files changed
+84
-1
No files matched your search
@@ -277,4 +277,29 @@ describe("StorageService", () => {
|
||||
/Storage is locked/,
|
||||
);
|
||||
});
|
||||
|
||||
// hasStoredAccount lets the upload modal auto-unlock EXISTING storage on refresh
|
||||
// without unlock() creating a fresh account for users who never set it up (#51).
|
||||
test("hasStoredAccount() is false before setup, true after, and never creates an account", async () => {
|
||||
assert.strictEqual(
|
||||
await storageService.hasStoredAccount(pubkey),
|
||||
false,
|
||||
"no account before any unlock",
|
||||
);
|
||||
// A read-only existence check must not create an account.
|
||||
assert.strictEqual(await storageService.hasStoredAccount(pubkey), false);
|
||||
|
||||
await storageService.unlock(pubkey, { signer: mockSigner });
|
||||
assert.strictEqual(
|
||||
await storageService.hasStoredAccount(pubkey),
|
||||
true,
|
||||
"account exists after unlock persisted the encrypted master key",
|
||||
);
|
||||
|
||||
// Survives a lock (existence is on-disk, not the in-memory master key).
|
||||
storageService.lock(pubkey);
|
||||
assert.strictEqual(await storageService.hasStoredAccount(pubkey), true);
|
||||
|
||||
assert.strictEqual(await storageService.hasStoredAccount(""), false);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user