암호 키 등록 후 Refresh Token 업그레이드 구현

This commit is contained in:
static
2024-12-29 01:55:01 +09:00
parent af51f04b94
commit 516375142d
7 changed files with 77 additions and 4 deletions

View File

@@ -9,6 +9,7 @@
import {
createBlobFromKeyPairBase64,
requestPubKeyRegistration,
requestTokenUpgrade,
storeKeyPairPersistently,
} from "./service";
@@ -40,7 +41,12 @@
if (await requestPubKeyRegistration(data.pubKeyBase64, $keyPairStore.privateKey)) {
await storeKeyPairPersistently($keyPairStore);
await goto(data.redirectPath);
if (await requestTokenUpgrade(data.pubKeyBase64)) {
await goto(data.redirectPath);
} else {
// TODO: Error handling
}
} else {
// TODO: Error handling
}

View File

@@ -38,6 +38,17 @@ export const requestPubKeyRegistration = async (pubKeyBase64: string, privateKey
return res.ok;
};
export const requestTokenUpgrade = async (pubKeyBase64: string) => {
const res = await fetch("/api/auth/upgradeToken", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ pubKey: pubKeyBase64 }),
});
return res.ok;
};
export const storeKeyPairPersistently = async (keyPair: CryptoKeyPair) => {
await storeKeyPairIntoIndexedDB(keyPair.publicKey, keyPair.privateKey);
};