mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-15 06:18:48 +00:00
암호 키 유무에 따른 자동 리다이렉션 구현
This commit is contained in:
@@ -9,8 +9,7 @@ export const init: ServerInit = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const handle: Handle = async ({ event, resolve }) => {
|
export const handle: Handle = async ({ event, resolve }) => {
|
||||||
const path = event.url.pathname;
|
if (["/api", "/auth"].some((path) => event.url.pathname.startsWith(path))) {
|
||||||
if (path.startsWith("/api") || path.startsWith("/auth")) {
|
|
||||||
return await resolve(event);
|
return await resolve(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,6 +17,9 @@ export const handle: Handle = async ({ event, resolve }) => {
|
|||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
return await resolve(event);
|
return await resolve(event);
|
||||||
} else {
|
} else {
|
||||||
redirect(302, "/auth/login?redirect=" + encodeURIComponent(path));
|
redirect(
|
||||||
|
302,
|
||||||
|
"/auth/login?redirect=" + encodeURIComponent(event.url.pathname + event.url.search),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { get } from "svelte/store";
|
||||||
import { goto } from "$app/navigation";
|
import { goto } from "$app/navigation";
|
||||||
import { Button, TextButton } from "$lib/components/buttons";
|
import { Button, TextButton } from "$lib/components/buttons";
|
||||||
import { TitleDiv, BottomDiv } from "$lib/components/divs";
|
import { TitleDiv, BottomDiv } from "$lib/components/divs";
|
||||||
import { TextInput } from "$lib/components/inputs";
|
import { TextInput } from "$lib/components/inputs";
|
||||||
|
import { keyPairStore } from "$lib/stores";
|
||||||
import { requestLogin } from "./service";
|
import { requestLogin } from "./service";
|
||||||
|
|
||||||
let { data } = $props();
|
let { data } = $props();
|
||||||
@@ -13,9 +15,12 @@
|
|||||||
const login = async () => {
|
const login = async () => {
|
||||||
// TODO: Validation
|
// TODO: Validation
|
||||||
|
|
||||||
const ok = await requestLogin(email, password);
|
if (await requestLogin(email, password)) {
|
||||||
if (ok) {
|
await goto(
|
||||||
goto(data.redirectPath);
|
get(keyPairStore)
|
||||||
|
? data.redirectPath
|
||||||
|
: "/key/generate?redirect=" + encodeURIComponent(data.redirectPath),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// TODO: Alert
|
// TODO: Alert
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { storeKeyPairIntoIndexedDB } from "$lib/indexedDB";
|
|
||||||
import { keyPairStore } from "$lib/stores";
|
import { keyPairStore } from "$lib/stores";
|
||||||
|
|
||||||
type KeyType = "public" | "private";
|
type KeyType = "public" | "private";
|
||||||
@@ -48,7 +47,6 @@ export const generateKeyPair = async () => {
|
|||||||
publicKey: keyPair.publicKey,
|
publicKey: keyPair.publicKey,
|
||||||
privateKey: privKeySecured,
|
privateKey: privKeySecured,
|
||||||
});
|
});
|
||||||
await storeKeyPairIntoIndexedDB(keyPair.publicKey, privKeySecured);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pubKeyBase64: await exportKeyToBase64(keyPair.publicKey, "public"),
|
pubKeyBase64: await exportKeyToBase64(keyPair.publicKey, "public"),
|
||||||
|
|||||||
@@ -1,6 +1,22 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
import { goto } from "$app/navigation";
|
||||||
|
import { getKeyPairFromIndexedDB } from "$lib/indexedDB";
|
||||||
|
import { keyPairStore } from "$lib/stores";
|
||||||
import "../app.css";
|
import "../app.css";
|
||||||
|
|
||||||
let { children } = $props();
|
let { children } = $props();
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
const { pubKey, privKey } = await getKeyPairFromIndexedDB();
|
||||||
|
if (pubKey && privKey) {
|
||||||
|
keyPairStore.set({ publicKey: pubKey, privateKey: privKey });
|
||||||
|
} else if (!["/auth", "/key/generate"].some((path) => location.pathname.startsWith(path))) {
|
||||||
|
await goto(
|
||||||
|
"/key/generate?redirect=" + encodeURIComponent(location.pathname + location.search),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{@render children()}
|
{@render children()}
|
||||||
|
|||||||
Reference in New Issue
Block a user