로그인 및 암호 키 등록 이후 클라이언트 승인 대기 페이지로의 자동 리다이렉션 구현

This commit is contained in:
static
2024-12-31 22:32:24 +09:00
parent e5cbd46b35
commit e8e4022bc2
5 changed files with 58 additions and 52 deletions

View File

@@ -5,28 +5,35 @@
import { TitleDiv, BottomDiv } from "$lib/components/divs";
import { TextInput } from "$lib/components/inputs";
import { refreshToken } from "$lib/hooks/callAPI";
import { clientKeyStore } from "$lib/stores";
import { requestLogin, requestTokenUpgrade } from "./service";
import { clientKeyStore, masterKeyStore } from "$lib/stores";
import { requestLogin, requestTokenUpgrade, requestMasterKeyDownload } from "./service";
let { data } = $props();
let email = $state("");
let password = $state("");
const redirect = async (url: string) => {
return await goto(`${url}?redirect=${encodeURIComponent(data.redirectPath)}`);
};
const login = async () => {
// TODO: Validation
try {
if (!(await requestLogin(email, password))) throw new Error("Failed to login");
if ($clientKeyStore && !(await requestTokenUpgrade($clientKeyStore)))
throw new Error("Failed to upgrade token");
if (!$clientKeyStore) return await redirect("/key/generate");
await goto(
$clientKeyStore
? data.redirectPath
: "/key/generate?redirect=" + encodeURIComponent(data.redirectPath),
);
if (!(await requestTokenUpgrade($clientKeyStore))) throw new Error("Failed to upgrade token");
// TODO: Multi-user support
if ($masterKeyStore || (await requestMasterKeyDownload($clientKeyStore.decryptKey))) {
await goto(data.redirectPath);
} else {
await redirect("/client/pending");
}
} catch (e) {
// TODO: Alert
throw e;