From d56d20d0beae9401a9131a367201fef435387b26 Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 Date: Mon, 15 May 2023 15:22:35 +0000 Subject: [PATCH] Redirect from pages that require auth on logout (#1016) * Redirect fomr pages that require auth on logout * Extract helper function --------- Co-authored-by: Dessalines --- src/shared/services/UserService.ts | 8 ++++++-- src/shared/utils.ts | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/shared/services/UserService.ts b/src/shared/services/UserService.ts index e4ec5f9..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,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 { diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 4e5f74b..d65d2d3 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -1589,3 +1589,9 @@ export function getQueryString>( "?" ); } + +export function isAuthPath(pathname: string) { + return /create_.*|inbox|settings|setup|admin|reports|registration_applications/g.test( + pathname + ); +} -- 2.44.1