From 82926ab17207da5b7e624c5e76608fe6d74ee033 Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Tue, 26 Apr 2022 22:45:40 +0300 Subject: [PATCH] frontend: add auth overlays --- frontend/public/global.css | 4 + frontend/src/auth.js | 22 +++++ .../components/overlays/CreateAccount.svelte | 77 ++++++++++++++++++ frontend/src/components/overlays/Login.svelte | 81 +++++++++++++++++++ .../overlays/OverlayProvider.svelte | 10 ++- frontend/src/components/overlays/Toast.svelte | 1 + frontend/src/gateway.js | 41 +++++++--- frontend/src/main.js | 5 +- frontend/src/storage.js | 3 +- frontend/src/stores.js | 5 +- 10 files changed, 232 insertions(+), 17 deletions(-) create mode 100644 frontend/src/auth.js create mode 100644 frontend/src/components/overlays/CreateAccount.svelte create mode 100644 frontend/src/components/overlays/Login.svelte diff --git a/frontend/public/global.css b/frontend/public/global.css index 6be0050..013a60a 100644 --- a/frontend/public/global.css +++ b/frontend/public/global.css @@ -115,6 +115,10 @@ body { transform: translate(-50%, -50%); } +.modal-backdrop-opaque { + background-color: var(--background-color-1); +} + .modal { display: flex; flex-direction: column; diff --git a/frontend/src/auth.js b/frontend/src/auth.js new file mode 100644 index 0000000..2396204 --- /dev/null +++ b/frontend/src/auth.js @@ -0,0 +1,22 @@ +import gateway, { GatewayEventType } from "./gateway"; +import { setAuthToken } from "./storage"; +import { overlayStore } from "./stores"; + +function useAuthHandlers() { + gateway.subscribe(GatewayEventType.Ready, () => { + overlayStore.close("login"); + overlayStore.close("createAccount"); + }); + + gateway.subscribe(GatewayEventType.BadAuth, () => { + overlayStore.open("login", {}); + }); +} + +export function authWithToken(token, shouldUpdate=false) { + if (shouldUpdate) + setAuthToken(token); + gateway.init(token); +} + +useAuthHandlers(); diff --git a/frontend/src/components/overlays/CreateAccount.svelte b/frontend/src/components/overlays/CreateAccount.svelte new file mode 100644 index 0000000..872cd2b --- /dev/null +++ b/frontend/src/components/overlays/CreateAccount.svelte @@ -0,0 +1,77 @@ + + + + +