mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 06:58:46 +00:00
로그인 및 암호 키 등록 이후 클라이언트 승인 대기 페이지로의 자동 리다이렉션 구현
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user