From a2473680d4ce6f7797d58b27d4f8ab14d9dc9210 Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 Date: Thu, 5 Oct 2023 19:38:10 +0000 Subject: [PATCH] fix: Prevent login screen from redirecting to signup (#2170) --- src/shared/components/app/app.tsx | 7 ++++- .../components/common/anonymous-guard.tsx | 31 +++++++++++++++++++ .../components/common/subscribe-button.tsx | 2 ++ src/shared/components/common/totp-modal.tsx | 1 + src/shared/components/home/login-reset.tsx | 8 +---- src/shared/components/home/login.tsx | 7 ----- src/shared/utils/app/index.ts | 2 ++ src/shared/utils/app/is-anonymous-path.ts | 5 +++ 8 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 src/shared/components/common/anonymous-guard.tsx create mode 100644 src/shared/utils/app/is-anonymous-path.ts diff --git a/src/shared/components/app/app.tsx b/src/shared/components/app/app.tsx index b2f0df43..323be486 100644 --- a/src/shared/components/app/app.tsx +++ b/src/shared/components/app/app.tsx @@ -1,4 +1,4 @@ -import { isAuthPath, setIsoData } from "@utils/app"; +import { isAnonymousPath, isAuthPath, setIsoData } from "@utils/app"; import { dataBsTheme } from "@utils/browser"; import { Component, RefObject, createRef, linkEvent } from "inferno"; import { Provider } from "inferno-i18next-dess"; @@ -14,6 +14,7 @@ import { Footer } from "./footer"; import { Navbar } from "./navbar"; import "./styles.scss"; import { Theme } from "./theme"; +import AnonymousGuard from "../common/anonymous-guard"; interface AppProps { user?: MyUserInfo; @@ -78,6 +79,10 @@ export class App extends Component { + ) : isAnonymousPath(path ?? "") ? ( + + + ) : ( ))} diff --git a/src/shared/components/common/anonymous-guard.tsx b/src/shared/components/common/anonymous-guard.tsx new file mode 100644 index 00000000..70a1f7aa --- /dev/null +++ b/src/shared/components/common/anonymous-guard.tsx @@ -0,0 +1,31 @@ +import { Component } from "inferno"; +import { UserService } from "../../services"; +import { Spinner } from "./icon"; + +interface AnonymousGuardState { + hasRedirected: boolean; +} + +class AnonymousGuard extends Component { + state = { + hasRedirected: false, + } as AnonymousGuardState; + + constructor(props: any, context: any) { + super(props, context); + } + + componentDidMount() { + if (UserService.Instance.myUserInfo) { + this.context.router.history.replace(`/`); + } else { + this.setState({ hasRedirected: true }); + } + } + + render() { + return this.state.hasRedirected ? this.props.children : ; + } +} + +export default AnonymousGuard; diff --git a/src/shared/components/common/subscribe-button.tsx b/src/shared/components/common/subscribe-button.tsx index 9ae4426f..58195391 100644 --- a/src/shared/components/common/subscribe-button.tsx +++ b/src/shared/components/common/subscribe-button.tsx @@ -201,6 +201,8 @@ class RemoteFetchModal extends Component< value={this.state.instanceText} onInput={linkEvent(this, handleInput)} required + enterKeyHint="go" + inputMode="url" />