From ab3fed3ddf7e0141985ebda761fd6e3085516ede Mon Sep 17 00:00:00 2001
From: abias <abias1122@gmail.com>
Date: Sat, 13 May 2023 23:09:05 -0400
Subject: [PATCH] Extract helper function

---
 src/shared/services/UserService.ts | 8 ++------
 src/shared/utils.ts                | 6 ++++++
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/shared/services/UserService.ts b/src/shared/services/UserService.ts
index b5f8d26..16540f2 100644
--- a/src/shared/services/UserService.ts
+++ b/src/shared/services/UserService.ts
@@ -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,11 +48,7 @@ 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;
-    if (
-      /create_.*|inbox|settings|setup|admin|reports|registration_applications/g.test(
-        location.pathname
-      )
-    ) {
+    if (isAuthPath(location.pathname)) {
       location.replace("/");
     } else {
       location.reload();
diff --git a/src/shared/utils.ts b/src/shared/utils.ts
index ec6d92d..821d22f 100644
--- a/src/shared/utils.ts
+++ b/src/shared/utils.ts
@@ -1603,3 +1603,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
+  );
+}
-- 
2.44.1