From 689ddf78bf3e90f4bd9ad7076fd016669fa74309 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Wed, 31 Jan 2024 17:09:50 +0700 Subject: [PATCH 1/5] UBERF-5235: Fixes for login form Signed-off-by: Andrey Sobolev --- packages/core/src/client.ts | 2 +- plugins/client-resources/src/index.ts | 61 +++++---- .../src/components/Confirmation.svelte | 5 +- .../src/components/CreateWorkspaceForm.svelte | 1 + .../src/components/Join.svelte | 6 +- .../src/components/LoginApp.svelte | 1 + .../src/components/LoginForm.svelte | 120 ++++++++++++------ .../src/components/SelectWorkspace.svelte | 5 +- .../src/components/SignupForm.svelte | 3 +- plugins/login-resources/src/utils.ts | 14 +- plugins/login/src/index.ts | 4 + .../src/components/Settings.svelte | 1 + plugins/workbench-resources/src/connect.ts | 1 + plugins/workbench-resources/src/utils.ts | 1 + server/account/src/index.ts | 22 +++- 15 files changed, 163 insertions(+), 84 deletions(-) diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts index eaed3821ee..7c5c4793b9 100644 --- a/packages/core/src/client.ts +++ b/packages/core/src/client.ts @@ -229,7 +229,7 @@ export async function createClient ( let lastTx: number function txHandler (tx: Tx): void { - if (tx === null) { + if (tx == null) { return } if (client === null) { diff --git a/plugins/client-resources/src/index.ts b/plugins/client-resources/src/index.ts index a4d0a24ed5..dfd592194a 100644 --- a/plugins/client-resources/src/index.ts +++ b/plugins/client-resources/src/index.ts @@ -18,6 +18,7 @@ import core, { AccountClient, ClientConnectEvent, TxHandler, + TxPersistenceStore, TxWorkspaceEvent, WorkspaceEvent, createClient @@ -68,34 +69,7 @@ export default async () => { return connect(url.href, upgradeHandler, onUpgrade, onUnauthorized, onConnect) }, filterModel ? [...getPlugins(), ...(getMetadata(clientPlugin.metadata.ExtraPlugins) ?? [])] : undefined, - { - load: async () => { - if (typeof localStorage !== 'undefined') { - const storedValue = localStorage.getItem('platform.model') ?? null - try { - const model = storedValue != null ? JSON.parse(storedValue) : undefined - if (token !== model?.token) { - return { - full: false, - transactions: [], - hash: [] - } - } - return model.model - } catch {} - } - return { - full: true, - transactions: [], - hash: [] - } - }, - store: async (model) => { - if (typeof localStorage !== 'undefined') { - localStorage.setItem('platform.model', JSON.stringify({ token, model })) - } - } - } + createModelPersistence(token) ) // Check if we had dev hook for client. client = hookClient(client) @@ -104,6 +78,37 @@ export default async () => { } } } +function createModelPersistence (token: string): TxPersistenceStore | undefined { + return { + load: async () => { + if (typeof localStorage !== 'undefined') { + const storedValue = localStorage.getItem('platform.model') ?? null + try { + const model = storedValue != null ? JSON.parse(storedValue) : undefined + if (token !== model?.token) { + return { + full: false, + transactions: [], + hash: [] + } + } + return model.model + } catch {} + } + return { + full: true, + transactions: [], + hash: [] + } + }, + store: async (model) => { + if (typeof localStorage !== 'undefined') { + localStorage.setItem('platform.model', JSON.stringify({ token, model })) + } + } + } +} + async function hookClient (client: Promise): Promise { const hook = getMetadata(clientPlugin.metadata.ClientHook) if (hook !== undefined) { diff --git a/plugins/login-resources/src/components/Confirmation.svelte b/plugins/login-resources/src/components/Confirmation.svelte index 121e5610db..43a250ed94 100644 --- a/plugins/login-resources/src/components/Confirmation.svelte +++ b/plugins/login-resources/src/components/Confirmation.svelte @@ -31,7 +31,7 @@ navigate(loc) } - function goToLogin () { + function goToLogin (): void { const loc = getCurrentLocation() loc.query = undefined loc.path[1] = 'login' @@ -39,7 +39,7 @@ navigate(loc) } - async function check () { + async function check (): Promise { const location = getCurrentLocation() if (location.query?.id === undefined || location.query?.id === null) return status = new Status(Severity.INFO, login.status.ConnectingToServer, {}) @@ -50,6 +50,7 @@ if (result !== undefined) { setMetadata(presentation.metadata.Token, result.token) + setMetadataLocalStorage(login.metadata.LastToken, result.token) setMetadataLocalStorage(login.metadata.LoginEndpoint, result.endpoint) setMetadataLocalStorage(login.metadata.LoginEmail, result.email) goToWorkspaces() diff --git a/plugins/login-resources/src/components/CreateWorkspaceForm.svelte b/plugins/login-resources/src/components/CreateWorkspaceForm.svelte index 3e21a71aa2..8c4b6d228f 100644 --- a/plugins/login-resources/src/components/CreateWorkspaceForm.svelte +++ b/plugins/login-resources/src/components/CreateWorkspaceForm.svelte @@ -89,6 +89,7 @@ if (result !== undefined) { setMetadata(presentation.metadata.Token, result.token) + setMetadataLocalStorage(login.metadata.LastToken, result.token) const tokens: Record = fetchMetadataLocalStorage(login.metadata.LoginTokens) ?? {} tokens[object.workspace] = result.token setMetadataLocalStorage(login.metadata.LoginTokens, tokens) diff --git a/plugins/login-resources/src/components/Join.svelte b/plugins/login-resources/src/components/Join.svelte index 51b7b67445..06ad18761a 100644 --- a/plugins/login-resources/src/components/Join.svelte +++ b/plugins/login-resources/src/components/Join.svelte @@ -75,6 +75,7 @@ if (result !== undefined) { setMetadata(presentation.metadata.Token, result.token) + setMetadataLocalStorage(login.metadata.LastToken, result.token) const tokens: Record = fetchMetadataLocalStorage(login.metadata.LoginTokens) ?? {} tokens[result.workspace] = result.token setMetadataLocalStorage(login.metadata.LoginTokens, tokens) @@ -128,10 +129,10 @@ } onMount(() => { - check() + void check() }) - async function check () { + async function check (): Promise { if (location.query?.inviteId === undefined || location.query?.inviteId === null) return status = new Status(Severity.INFO, login.status.ConnectingToServer, {}) const [, result] = await checkJoined(location.query.inviteId) @@ -139,6 +140,7 @@ if (result !== undefined) { const tokens: Record = fetchMetadataLocalStorage(login.metadata.LoginTokens) ?? {} setMetadata(presentation.metadata.Token, result.token) + setMetadataLocalStorage(login.metadata.LastToken, result.token) tokens[result.workspace] = result.token setMetadataLocalStorage(login.metadata.LoginTokens, tokens) setMetadataLocalStorage(login.metadata.LoginEndpoint, result.endpoint) diff --git a/plugins/login-resources/src/components/LoginApp.svelte b/plugins/login-resources/src/components/LoginApp.svelte index 56228b0172..afaeb9546a 100644 --- a/plugins/login-resources/src/components/LoginApp.svelte +++ b/plugins/login-resources/src/components/LoginApp.svelte @@ -63,6 +63,7 @@ onDestroy( location.subscribe((loc) => { void (async (loc) => { + token = getMetadata(presentation.metadata.Token) page = loc.path[1] ?? (token ? 'selectWorkspace' : 'login') if (!pages.includes(page)) { page = 'login' diff --git a/plugins/login-resources/src/components/LoginForm.svelte b/plugins/login-resources/src/components/LoginForm.svelte index d3866d0092..3f06c662a2 100644 --- a/plugins/login-resources/src/components/LoginForm.svelte +++ b/plugins/login-resources/src/components/LoginForm.svelte @@ -14,13 +14,21 @@ // limitations under the License. -->
- +
+
+ {account?.email} +
diff --git a/plugins/login-resources/src/components/SignupForm.svelte b/plugins/login-resources/src/components/SignupForm.svelte index 102c4c5bc2..f91d0bd3a2 100644 --- a/plugins/login-resources/src/components/SignupForm.svelte +++ b/plugins/login-resources/src/components/SignupForm.svelte @@ -16,7 +16,7 @@ - +