diff --git a/src/lib/GoogleAuth.svelte b/src/lib/GoogleAuth.svelte index 8976add..39c4b56 100644 --- a/src/lib/GoogleAuth.svelte +++ b/src/lib/GoogleAuth.svelte @@ -8,33 +8,44 @@ import Icon from "@iconify/svelte"; import { createLitSession } from "./createLitSession"; import { connectProvider } from "./setupLit"; + import Signer from "./Signer.svelte"; const redirectUri = "http://localhost:3000/"; let sessionSigs = null; - let litNodeClient, error, currentPKP, authMethod, provider; + let error, currentPKP, authMethod, provider; let status = "Initializing..."; let pkps: IRelayPKP[] = []; let view = "SIGN_IN"; - let sessionSigsObject; + let sessionStatuses; + let activeSession = null; + + let messageToSign = { user: "Sam", loggedIn: true }; onMount(async () => { - // litNodeClient = new LitNodeClient({ litNetwork: "serrano" }); - // await litNodeClient.connect(); - const sessionSigsLocalStorage = localStorage.getItem("google-signature"); - const currentPKPLocalStorage = localStorage.getItem("current-pkp"); - if (sessionSigsLocalStorage && currentPKPLocalStorage) { - sessionSigs = JSON.parse(sessionSigsLocalStorage); - currentPKP = JSON.parse(currentPKPLocalStorage); - } else { - initialize(); - } - if (sessionSigsLocalStorage) { - sessionSigsObject = JSON.parse(sessionSigsLocalStorage); - } + initialize(); }); $: if (sessionSigs) { + // Update sessionStatuses + sessionStatuses = Object.entries(sessionSigs).map(([node, data]) => { + const sessionKey = JSON.parse(data.signedMessage).sessionKey; + const expiration = new Date(JSON.parse(data.signedMessage).expiration); + const isExpired = expiration < new Date(); + return { + node, + sessionKey, + expiration: expiration.toISOString(), + isExpired, + }; + }); + + // Find an active session and store it in local storage + activeSession = sessionStatuses.find(({ isExpired }) => !isExpired); + if (activeSession) { + localStorage.setItem("google-session", JSON.stringify(activeSession)); + } + view = "READY"; } @@ -133,29 +144,26 @@
{currentPKP.ethAddress}
- {/if} -{status}
-+ {isExpired ? "🔴" : "🟢"} Node: {node}, Session Key: {sessionKey}, + Expiration: {expiration} +
+ {/each} + {/if} +{status}
+