]> Untitled Git - lemmy-ui.git/commitdiff
Redirect from pages that require auth on logout (#1016)
authorSleeplessOne1917 <abias1122@gmail.com>
Mon, 15 May 2023 15:22:35 +0000 (15:22 +0000)
committerGitHub <noreply@github.com>
Mon, 15 May 2023 15:22:35 +0000 (11:22 -0400)
* Redirect fomr pages that require auth on logout

* Extract helper function

---------

Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
src/shared/services/UserService.ts
src/shared/utils.ts

index e4ec5f987069a60aa37162dc7b53ac34bbc60a01..16540f2373dd20f1a3162912ac8e6dc274dd2f3f 100644 (file)
@@ -5,7 +5,7 @@ import { LoginResponse, MyUserInfo } from "lemmy-js-client";
 import { BehaviorSubject } from "rxjs";
 import { isHttps } from "../env";
 import { i18n } from "../i18next";
-import { isBrowser, toast } from "../utils";
+import { isAuthPath, isBrowser, toast } from "../utils";
 
 interface Claims {
   sub: number;
@@ -48,7 +48,11 @@ export class UserService {
     this.myUserInfo = undefined;
     IsomorphicCookie.remove("jwt"); // TODO is sometimes unreliable for some reason
     document.cookie = "jwt=; Max-Age=0; path=/; domain=" + location.hostname;
-    location.reload();
+    if (isAuthPath(location.pathname)) {
+      location.replace("/");
+    } else {
+      location.reload();
+    }
   }
 
   public auth(throwErr = true): string | undefined {
index 4e5f74b4f39abea19cde41612d7836bf70eab059..d65d2d3739718d14985fdc2198ad04971e8ad57c 100644 (file)
@@ -1589,3 +1589,9 @@ export function getQueryString<T extends Record<string, string | undefined>>(
       "?"
     );
 }
+
+export function isAuthPath(pathname: string) {
+  return /create_.*|inbox|settings|setup|admin|reports|registration_applications/g.test(
+    pathname
+  );
+}