mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-22 06:36:17 +00:00
Use auth
cookie set by backend instead of jwt
(fixes #2193)
Requires https://github.com/LemmyNet/lemmy-js-client/pull/208
This commit is contained in:
parent
acfcd86b9b
commit
442766c1d8
|
@ -26,7 +26,7 @@ export const updateUnreadCountsInterval = 30000;
|
|||
export const fetchLimit = 20;
|
||||
export const relTags = "noopener nofollow";
|
||||
export const emDash = "\u2014";
|
||||
export const authCookieName = "jwt";
|
||||
export const authCookieName = "auth";
|
||||
|
||||
// No. of max displayed communities per
|
||||
// page on route "/communities"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { isAuthPath } from "@utils/app";
|
||||
import { clearAuthCookie, isBrowser, setAuthCookie } from "@utils/browser";
|
||||
import { isBrowser } from "@utils/browser";
|
||||
import * as cookie from "cookie";
|
||||
import jwt_decode from "jwt-decode";
|
||||
import { LoginResponse, MyUserInfo } from "lemmy-js-client";
|
||||
|
@ -40,7 +40,6 @@ export class UserService {
|
|||
|
||||
if (isBrowser() && res.jwt) {
|
||||
showToast && toast(I18NextService.i18n.t("logged_in"));
|
||||
setAuthCookie(res.jwt);
|
||||
this.#setJwtInfo();
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +49,9 @@ export class UserService {
|
|||
this.myUserInfo = undefined;
|
||||
|
||||
if (isBrowser()) {
|
||||
clearAuthCookie();
|
||||
// TODO: call logout here
|
||||
// https://github.com/LemmyNet/lemmy-js-client/pull/208
|
||||
//HttpService.client.logout()
|
||||
}
|
||||
|
||||
if (isAuthPath(location.pathname)) {
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
import * as cookie from "cookie";
|
||||
import { authCookieName } from "../../config";
|
||||
|
||||
export default function clearAuthCookie() {
|
||||
document.cookie = cookie.serialize(authCookieName, "", {
|
||||
maxAge: -1,
|
||||
sameSite: true,
|
||||
path: "/",
|
||||
});
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
import canShare from "./can-share";
|
||||
import clearAuthCookie from "./clear-auth-cookie";
|
||||
import dataBsTheme from "./data-bs-theme";
|
||||
import isBrowser from "./is-browser";
|
||||
import isDark from "./is-dark";
|
||||
|
@ -7,12 +6,10 @@ import loadCss from "./load-css";
|
|||
import platform from "./platform";
|
||||
import restoreScrollPosition from "./restore-scroll-position";
|
||||
import saveScrollPosition from "./save-scroll-position";
|
||||
import setAuthCookie from "./set-auth-cookie";
|
||||
import share from "./share";
|
||||
|
||||
export {
|
||||
canShare,
|
||||
clearAuthCookie,
|
||||
dataBsTheme,
|
||||
isBrowser,
|
||||
isDark,
|
||||
|
@ -20,6 +17,5 @@ export {
|
|||
platform,
|
||||
restoreScrollPosition,
|
||||
saveScrollPosition,
|
||||
setAuthCookie,
|
||||
share,
|
||||
};
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
import { isHttps } from "@utils/env";
|
||||
import * as cookie from "cookie";
|
||||
import { authCookieName } from "../../config";
|
||||
|
||||
export default function setAuthCookie(jwt: string) {
|
||||
document.cookie = cookie.serialize(authCookieName, jwt, {
|
||||
maxAge: 365 * 24 * 60 * 60 * 1000,
|
||||
secure: isHttps(),
|
||||
sameSite: true,
|
||||
path: "/",
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue