Skip to content

Commit

Permalink
Redirect from pages that require auth on logout (#1016)
Browse files Browse the repository at this point in the history
* Redirect fomr pages that require auth on logout

* Extract helper function

---------

Co-authored-by: Dessalines <[email protected]>
  • Loading branch information
SleeplessOne1917 and dessalines authored May 15, 2023
1 parent 1683a74 commit d56d20d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/shared/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

0 comments on commit d56d20d

Please sign in to comment.