mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 06:58:46 +00:00
Store 초기화를 hooks.client.ts에서 수행하도록 변경
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
import { TitleDiv } from "$lib/components/divs";
|
||||
import { clientKeyStore, masterKeyStore } from "$lib/stores";
|
||||
@@ -14,17 +15,13 @@
|
||||
: undefined,
|
||||
);
|
||||
|
||||
$effect(() => {
|
||||
if ($masterKeyStore) {
|
||||
goto(data.redirectPath);
|
||||
} else if ($clientKeyStore) {
|
||||
requestMasterKeyDownload($clientKeyStore.decryptKey, $clientKeyStore.verifyKey).then(
|
||||
async (ok) => {
|
||||
if (ok) {
|
||||
return await goto(data.redirectPath);
|
||||
}
|
||||
},
|
||||
);
|
||||
onMount(async () => {
|
||||
if (
|
||||
$masterKeyStore ||
|
||||
($clientKeyStore &&
|
||||
(await requestMasterKeyDownload($clientKeyStore.decryptKey, $clientKeyStore.verifyKey)))
|
||||
) {
|
||||
await goto(data.redirectPath);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
import { Button, TextButton } from "$lib/components/buttons";
|
||||
import { TitleDiv, BottomDiv } from "$lib/components/divs";
|
||||
@@ -44,9 +45,9 @@
|
||||
});
|
||||
};
|
||||
|
||||
$effect(() => {
|
||||
onMount(async () => {
|
||||
if ($clientKeyStore) {
|
||||
goto(data.redirectPath);
|
||||
await goto(data.redirectPath);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -1,24 +1,25 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
import { goto as svelteGoto } from "$app/navigation";
|
||||
import { clientKeyStore, masterKeyStore } from "$lib/stores";
|
||||
import "../app.css";
|
||||
import { prepareClientKeyStore, prepareMasterKeyStore } from "./services";
|
||||
|
||||
let { children } = $props();
|
||||
|
||||
onMount(async () => {
|
||||
const redirect = async (url: string) => {
|
||||
const goto = async (url: string) => {
|
||||
const whitelist = ["/auth", "/key", "/client/pending"];
|
||||
if (!whitelist.some((path) => location.pathname.startsWith(path))) {
|
||||
await goto(`${url}?redirect=${encodeURIComponent(location.pathname + location.search)}`);
|
||||
await svelteGoto(
|
||||
`${url}?redirect=${encodeURIComponent(location.pathname + location.search)}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
if (!(await prepareClientKeyStore())) {
|
||||
return await redirect("/key/generate");
|
||||
}
|
||||
if (!(await prepareMasterKeyStore())) {
|
||||
return await redirect("/client/pending");
|
||||
if (!$clientKeyStore) {
|
||||
await goto("/key/generate");
|
||||
} else if (!$masterKeyStore) {
|
||||
await goto("/client/pending");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
import { getClientKey, getMasterKeys } from "$lib/indexedDB";
|
||||
import { clientKeyStore, masterKeyStore } from "$lib/stores";
|
||||
|
||||
export const prepareClientKeyStore = async () => {
|
||||
const encryptKey = await getClientKey("encrypt");
|
||||
const decryptKey = await getClientKey("decrypt");
|
||||
const signKey = await getClientKey("sign");
|
||||
const verifyKey = await getClientKey("verify");
|
||||
if (encryptKey && decryptKey && signKey && verifyKey) {
|
||||
clientKeyStore.set({ encryptKey, decryptKey, signKey, verifyKey });
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const prepareMasterKeyStore = async () => {
|
||||
const masterKeys = await getMasterKeys();
|
||||
if (masterKeys.length > 0) {
|
||||
masterKeyStore.set(
|
||||
new Map(masterKeys.map(({ version, state, key }) => [version, { version, state, key }])),
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user