]> Untitled Git - lemmy-ui.git/commitdiff
Extract helper function
authorabias <abias1122@gmail.com>
Sun, 14 May 2023 03:09:05 +0000 (23:09 -0400)
committerabias <abias1122@gmail.com>
Sun, 14 May 2023 03:09:05 +0000 (23:09 -0400)
src/shared/services/UserService.ts
src/shared/utils.ts

index b5f8d26040ab6307a6fa3293a777cc0fd15fd68a..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,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();
index ec6d92d1de000d9a644c9c867edd002542be5c84..821d22f3c5b978b6bf8e614d7a2497304193b9f3 100644 (file)
@@ -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
+  );
+}