fix redirect_after_login

master v0.1.0-preview.8
Niko PLP 4 months ago
parent e4b96d96e5
commit b4ea570146
  1. 23
      ng-app/src/lib/FullLayout.svelte
  2. 11
      ng-app/src/lib/MobileBottomBarItem.svelte
  3. 1
      ng-app/src/routes/User.svelte
  4. 17
      ng-app/src/routes/WalletLogin.svelte
  5. 3
      ng-app/src/store.ts

@ -35,6 +35,9 @@
import Message from "./components/Message.svelte"; import Message from "./components/Message.svelte";
import Signature from "./popups/Signature.svelte"; import Signature from "./popups/Signature.svelte";
import {
get,
} from "svelte/store";
// @ts-ignore // @ts-ignore
import { t } from "svelte-i18n"; import { t } from "svelte-i18n";
@ -47,7 +50,7 @@
in_private_store, show_doc_popup, cur_doc_popup, open_doc_popup } from "../tab"; in_private_store, show_doc_popup, cur_doc_popup, open_doc_popup } from "../tab";
import { import {
active_session, redirect_after_login, toasts, check_has_camera, toast_error, active_session, redirect_after_login, toasts, check_has_camera, toast_error,
reset_toasts, reset_toasts, redirect_if_wallet_is, active_wallet,
display_error, openModalCreate display_error, openModalCreate
} from "../store"; } from "../store";
import ZeraIcon from "./icons/ZeraIcon.svelte"; import ZeraIcon from "./icons/ZeraIcon.svelte";
@ -368,6 +371,7 @@
let shareMenu; let shareMenu;
let toolsMenu; let toolsMenu;
let unsub; let unsub;
let unsub2;
async function scrollToTop() { async function scrollToTop() {
await tick(); await tick();
if (top) top.scrollIntoView(); if (top) top.scrollIntoView();
@ -398,19 +402,22 @@
reset_toasts(); reset_toasts();
} }
}); });
unsub2 = active_session.subscribe((as) => {
if(!as) {
$redirect_after_login = $location;
$redirect_if_wallet_is = get(active_wallet)?.id
push("#/");
}
})
}); });
onDestroy(() => { onDestroy(() => {
if (unsub) unsub(); if (unsub) unsub();
if (unsub2) unsub2();
}); });
active_session.subscribe((as) => { if(!as) {
//console.log($location);
if ($location!="/user") {
$redirect_after_login = $location;
}
push("#/");
} })
$: activeUrl = "#" + $location; $: activeUrl = "#" + $location;

@ -13,6 +13,7 @@
import { getContext } from "svelte"; import { getContext } from "svelte";
import type { ComponentType } from "svelte"; import type { ComponentType } from "svelte";
import { Icon } from "svelte-heros-v2"; import { Icon } from "svelte-heros-v2";
import { onMount, onDestroy, tick } from "svelte";
export let href: string = ""; export let href: string = "";
export let icon: ComponentType; export let icon: ComponentType;
@ -22,8 +23,14 @@
}; };
let sidebarUrl = ""; let sidebarUrl = "";
activeUrlStore.subscribe((value) => { let unsub;
sidebarUrl = value; onMount( () => {
unsub = activeUrlStore.subscribe((value) => {
sidebarUrl = value;
});
});
onDestroy( () => {
if (unsub) unsub();
}); });
$: active = sidebarUrl ? href === sidebarUrl : false; $: active = sidebarUrl ? href === sidebarUrl : false;

@ -88,6 +88,7 @@
}); });
async function logout() { async function logout() {
await close_active_wallet(); await close_active_wallet();
} }

@ -34,7 +34,8 @@
has_wallets, has_wallets,
display_error, display_error,
wallet_from_import, wallet_from_import,
redirect_after_login redirect_after_login,
redirect_if_wallet_is
} from "../store"; } from "../store";
import { CheckBadge, ExclamationTriangle, QrCode } from "svelte-heros-v2"; import { CheckBadge, ExclamationTriangle, QrCode } from "svelte-heros-v2";
@ -110,10 +111,18 @@
async function loggedin() { async function loggedin() {
step = "loggedin"; step = "loggedin";
if ($redirect_after_login) { if ($redirect_after_login) {
let redir=$redirect_after_login; if (!$redirect_if_wallet_is || $redirect_if_wallet_is == $active_wallet?.id) {
$redirect_after_login=undefined; let redir=$redirect_after_login;
push("#"+redir); $redirect_after_login=undefined;
$redirect_if_wallet_is=undefined;
push("#"+redir);
} else {
$redirect_after_login=undefined;
$redirect_if_wallet_is=undefined;
push("#/");
}
} else { } else {
push("#/"); push("#/");
} }

@ -162,6 +162,7 @@ export const connections: Writable<Record<string, any>> = writable({});
export const active_session = writable(undefined); export const active_session = writable(undefined);
export const redirect_after_login = writable(undefined); export const redirect_after_login = writable(undefined);
export const redirect_if_wallet_is = writable(undefined);
export const connection_status: Writable<"disconnected" | "connected" | "connecting" | "starting"> = writable("starting"); export const connection_status: Writable<"disconnected" | "connected" | "connecting" | "starting"> = writable("starting");
@ -285,6 +286,8 @@ export const set_active_session = function(session) {
export { writable, readonly, derived }; export { writable, readonly, derived };
export const close_active_wallet = async function() { export const close_active_wallet = async function() {
redirect_after_login.set(undefined);
redirect_if_wallet_is.set(undefined);
if (next_reconnect) { if (next_reconnect) {
clearTimeout(next_reconnect); clearTimeout(next_reconnect);
next_reconnect = null; next_reconnect = null;

Loading…
Cancel
Save