From: abias Date: Sun, 14 May 2023 19:28:38 +0000 (-0400) Subject: Redirect to login and remove duplicated code X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%22https:/nerdica.net/%7B?a=commitdiff_plain;h=76f02928626217518709ec06b379e8f3ad2a964d;p=lemmy-ui.git Redirect to login and remove duplicated code --- diff --git a/src/server/index.tsx b/src/server/index.tsx index e724fbd..dab5341 100644 --- a/src/server/index.tsx +++ b/src/server/index.tsx @@ -141,7 +141,7 @@ server.get("/*", async (req, res) => { } if (!auth && isAuthPath(path)) { - res.redirect("/"); + res.redirect("/login"); return; } diff --git a/src/shared/components/common/auth-guard.tsx b/src/shared/components/common/auth-guard.tsx index ea7510a..bdddec7 100644 --- a/src/shared/components/common/auth-guard.tsx +++ b/src/shared/components/common/auth-guard.tsx @@ -4,7 +4,7 @@ import { UserService } from "../../services"; function AuthGuard(props: { children?: InfernoNode }) { if (!UserService.Instance.myUserInfo) { - return ; + return ; } else { return <>{props.children}; } diff --git a/src/shared/components/community/create-community.tsx b/src/shared/components/community/create-community.tsx index 81c6253..3650356 100644 --- a/src/shared/components/community/create-community.tsx +++ b/src/shared/components/community/create-community.tsx @@ -1,9 +1,7 @@ import { Component } from "inferno"; -import { Redirect } from "inferno-router"; import { CommunityView, GetSiteResponse } from "lemmy-js-client"; import { Subscription } from "rxjs"; import { i18n } from "../../i18next"; -import { UserService } from "../../services/UserService"; import { enableNsfw, isBrowser, @@ -50,7 +48,6 @@ export class CreateCommunity extends Component { render() { return (
- {!UserService.Instance.myUserInfo && } { this.handleSortChange = this.handleSortChange.bind(this); this.handlePageChange = this.handlePageChange.bind(this); - if (!UserService.Instance.myUserInfo && isBrowser()) { - toast(i18n.t("not_logged_in"), "danger"); - this.context.router.history.push(`/login`); - } - this.parseMessage = this.parseMessage.bind(this); this.subscription = wsSubscribe(this.parseMessage); diff --git a/src/shared/components/person/registration-applications.tsx b/src/shared/components/person/registration-applications.tsx index cd99bcc..b25c406 100644 --- a/src/shared/components/person/registration-applications.tsx +++ b/src/shared/components/person/registration-applications.tsx @@ -59,11 +59,6 @@ export class RegistrationApplications extends Component< this.handlePageChange = this.handlePageChange.bind(this); - if (!UserService.Instance.myUserInfo && isBrowser()) { - toast(i18n.t("not_logged_in"), "danger"); - this.context.router.history.push(`/login`); - } - this.parseMessage = this.parseMessage.bind(this); this.subscription = wsSubscribe(this.parseMessage); diff --git a/src/shared/components/person/reports.tsx b/src/shared/components/person/reports.tsx index 8fc3081..f4fc5a1 100644 --- a/src/shared/components/person/reports.tsx +++ b/src/shared/components/person/reports.tsx @@ -96,11 +96,6 @@ export class Reports extends Component { this.handlePageChange = this.handlePageChange.bind(this); - if (!UserService.Instance.myUserInfo && isBrowser()) { - toast(i18n.t("not_logged_in"), "danger"); - this.context.router.history.push(`/login`); - } - this.parseMessage = this.parseMessage.bind(this); this.subscription = wsSubscribe(this.parseMessage); diff --git a/src/shared/components/post/create-post.tsx b/src/shared/components/post/create-post.tsx index 2d0ba7e..d8a2cce 100644 --- a/src/shared/components/post/create-post.tsx +++ b/src/shared/components/post/create-post.tsx @@ -1,5 +1,4 @@ import { Component } from "inferno"; -import { Redirect } from "inferno-router"; import { RouteComponentProps } from "inferno-router/dist/Route"; import { GetCommunity, @@ -13,7 +12,7 @@ import { import { Subscription } from "rxjs"; import { InitialFetchRequest, PostFormParams } from "shared/interfaces"; import { i18n } from "../../i18next"; -import { UserService, WebSocketService } from "../../services"; +import { WebSocketService } from "../../services"; import { Choice, QueryParams, @@ -145,7 +144,6 @@ export class CreatePost extends Component< return (
- {!UserService.Instance.myUserInfo && }