Redirect from pages that require auth on logout (#1016)

* Redirect fomr pages that require auth on logout

* Extract helper function

---------

Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
This commit is contained in:
SleeplessOne1917 2023-05-15 15:22:35 +00:00 committed by GitHub
parent 1683a745b5
commit d56d20d0be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View 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 {

View 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
);
}