mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
web: fix app lock not getting disabled
This commit is contained in:
@@ -113,10 +113,7 @@ class KeyStore {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await this.metadataStore.delete(this.keyId);
|
await this.metadataStore.delete(this.keyId);
|
||||||
await this.metadataStore.set<SerializableCredential[]>("credentials", [
|
await this.setCredential({ id: credential.id, type: credential.type });
|
||||||
...(await this.getCredentials()),
|
|
||||||
{ id: credential.id, type: credential.type }
|
|
||||||
]);
|
|
||||||
|
|
||||||
this.key = originalKey;
|
this.key = originalKey;
|
||||||
return this;
|
return this;
|
||||||
@@ -128,7 +125,7 @@ class KeyStore {
|
|||||||
permanent?: boolean;
|
permanent?: boolean;
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
if (!(await this.isLocked())) return this;
|
if (!(await this.hasCredential(credential))) return;
|
||||||
|
|
||||||
const encryptedKey = await this.metadataStore.get<
|
const encryptedKey = await this.metadataStore.get<
|
||||||
Cipher<"base64"> | EncryptedData
|
Cipher<"base64"> | EncryptedData
|
||||||
@@ -147,9 +144,7 @@ class KeyStore {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (options?.permanent) {
|
if (options?.permanent) {
|
||||||
for (const credential of await this.getCredentials()) {
|
await this.resetCredentials();
|
||||||
await this.metadataStore.delete(this.getCredentialKey(credential));
|
|
||||||
}
|
|
||||||
await this.storeKey(key);
|
await this.storeKey(key);
|
||||||
this.key = undefined;
|
this.key = undefined;
|
||||||
} else this.key = key;
|
} else this.key = key;
|
||||||
@@ -228,6 +223,31 @@ class KeyStore {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async hasCredential(credential: SerializableCredential) {
|
||||||
|
const credentials = await this.getCredentials();
|
||||||
|
const index = credentials.findIndex(
|
||||||
|
(c) => c.type === credential.type && c.id === credential.id
|
||||||
|
);
|
||||||
|
return index > -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async resetCredentials() {
|
||||||
|
for (const credential of await this.getCredentials()) {
|
||||||
|
await this.metadataStore.delete(this.getCredentialKey(credential));
|
||||||
|
}
|
||||||
|
await this.metadataStore.delete("credentials");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async setCredential(credential: SerializableCredential) {
|
||||||
|
const credentials = await this.getCredentials();
|
||||||
|
const index = credentials.findIndex(
|
||||||
|
(c) => c.type === credential.type && c.id === credential.id
|
||||||
|
);
|
||||||
|
if (index > -1) return;
|
||||||
|
credentials.push(credential);
|
||||||
|
await this.metadataStore.set("credentials", credentials);
|
||||||
|
}
|
||||||
|
|
||||||
public async set(name: string, value: string) {
|
public async set(name: string, value: string) {
|
||||||
if (await this.isLocked())
|
if (await this.isLocked())
|
||||||
throw new Error("Please unlock the key store to set values.");
|
throw new Error("Please unlock the key store to set values.");
|
||||||
|
|||||||
@@ -83,7 +83,8 @@ export default function AppLock(props: PropsWithChildren<unknown>) {
|
|||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
height: "100%",
|
height: "100%",
|
||||||
flexDirection: "column"
|
flexDirection: "column",
|
||||||
|
overflowY: "auto"
|
||||||
}}
|
}}
|
||||||
onSubmit={async (e) => {
|
onSubmit={async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
Reference in New Issue
Block a user