]> Untitled Git - lemmy-ui.git/commitdiff
Redirect to login and remove duplicated code
authorabias <abias1122@gmail.com>
Sun, 14 May 2023 19:28:38 +0000 (15:28 -0400)
committerabias <abias1122@gmail.com>
Sun, 14 May 2023 19:28:38 +0000 (15:28 -0400)
src/server/index.tsx
src/shared/components/common/auth-guard.tsx
src/shared/components/community/create-community.tsx
src/shared/components/person/inbox.tsx
src/shared/components/person/registration-applications.tsx
src/shared/components/person/reports.tsx
src/shared/components/post/create-post.tsx
src/shared/components/private_message/create-private-message.tsx

index e724fbda1a848546983c4b335d36c97e19c74b5b..dab5341c9c9bbc350e04db9f5138e512f08bca3c 100644 (file)
@@ -141,7 +141,7 @@ server.get("/*", async (req, res) => {
     }
 
     if (!auth && isAuthPath(path)) {
-      res.redirect("/");
+      res.redirect("/login");
       return;
     }
 
index ea7510a8b450420eadb7c9856d8cbf836ac621bd..bdddec787b502c0ac19c0be515a7a5d22c00c0ae 100644 (file)
@@ -4,7 +4,7 @@ import { UserService } from "../../services";
 
 function AuthGuard(props: { children?: InfernoNode }) {
   if (!UserService.Instance.myUserInfo) {
-    return <Redirect to="/" />;
+    return <Redirect to="/login" />;
   } else {
     return <>{props.children}</>;
   }
index 81c62531a0d045339de094c7537840fb5779e02a..3650356876841261d2470999847215de1ebfc536 100644 (file)
@@ -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<any, CreateCommunityState> {
   render() {
     return (
       <div className="container-lg">
-        {!UserService.Instance.myUserInfo && <Redirect to="/login" />}
         <HtmlTags
           title={this.documentTitle}
           path={this.context.router.route.match.url}
index 10af488e6ad4c5b9eba3bb63548f8bf5e0d99d96..3c3e9484db5de5dfd6d8ced0547211750377dd5e 100644 (file)
@@ -111,11 +111,6 @@ export class Inbox extends Component<any, InboxState> {
     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);
 
index cd99bcc454aadb7b0d9ad2c4efbda242ef9ee317..b25c406a4e5d893aec287326b551f4e380ac1aa6 100644 (file)
@@ -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);
 
index 8fc30810898b9629a6652554d979ed4b4197d65a..f4fc5a1c016c8dc2d57691e911af58fd2f8f01f3 100644 (file)
@@ -96,11 +96,6 @@ export class Reports extends Component<any, ReportsState> {
 
     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);
 
index 2d0ba7e06c0a5ca13a8ca8175dc5d826d5838cc7..d8a2ccefb312266b41843a7d412abbeee2989aa3 100644 (file)
@@ -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 (
       <div className="container-lg">
-        {!UserService.Instance.myUserInfo && <Redirect to="/login" />}
         <HtmlTags
           title={this.documentTitle}
           path={this.context.router.route.match.url}
index 33bac433320e4899cb4da443f1d62f892f438ef5..327386cb665e88aa14fd576620cfe5a57fe5afd6 100644 (file)
@@ -10,7 +10,7 @@ import {
 import { Subscription } from "rxjs";
 import { i18n } from "../../i18next";
 import { InitialFetchRequest } from "../../interfaces";
-import { UserService, WebSocketService } from "../../services";
+import { WebSocketService } from "../../services";
 import {
   getRecipientIdFromProps,
   isBrowser,
@@ -51,11 +51,6 @@ export class CreatePrivateMessage extends Component<
     this.parseMessage = this.parseMessage.bind(this);
     this.subscription = wsSubscribe(this.parseMessage);
 
-    if (!UserService.Instance.myUserInfo && isBrowser()) {
-      toast(i18n.t("not_logged_in"), "danger");
-      this.context.router.history.push(`/login`);
-    }
-
     // Only fetch the data if coming from another route
     if (this.isoData.path == this.context.router.route.match.url) {
       this.state = {