From 442766c1d813950d178dceda317466bc3c581bee Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 31 Oct 2023 12:42:10 +0100 Subject: [PATCH 1/3] Use `auth` cookie set by backend instead of `jwt` (fixes #2193) Requires https://github.com/LemmyNet/lemmy-js-client/pull/208 --- src/shared/config.ts | 2 +- src/shared/services/UserService.ts | 7 ++++--- src/shared/utils/browser/clear-auth-cookie.ts | 10 ---------- src/shared/utils/browser/index.ts | 4 ---- src/shared/utils/browser/set-auth-cookie.ts | 12 ------------ 5 files changed, 5 insertions(+), 30 deletions(-) delete mode 100644 src/shared/utils/browser/clear-auth-cookie.ts delete mode 100644 src/shared/utils/browser/set-auth-cookie.ts diff --git a/src/shared/config.ts b/src/shared/config.ts index 70019742a..6718de0a7 100644 --- a/src/shared/config.ts +++ b/src/shared/config.ts @@ -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" diff --git a/src/shared/services/UserService.ts b/src/shared/services/UserService.ts index 3e459a1ac..e5d1afa84 100644 --- a/src/shared/services/UserService.ts +++ b/src/shared/services/UserService.ts @@ -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)) { diff --git a/src/shared/utils/browser/clear-auth-cookie.ts b/src/shared/utils/browser/clear-auth-cookie.ts deleted file mode 100644 index f5cc73f13..000000000 --- a/src/shared/utils/browser/clear-auth-cookie.ts +++ /dev/null @@ -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: "/", - }); -} diff --git a/src/shared/utils/browser/index.ts b/src/shared/utils/browser/index.ts index 41701207e..a35a81fee 100644 --- a/src/shared/utils/browser/index.ts +++ b/src/shared/utils/browser/index.ts @@ -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, }; diff --git a/src/shared/utils/browser/set-auth-cookie.ts b/src/shared/utils/browser/set-auth-cookie.ts deleted file mode 100644 index e7d4300ca..000000000 --- a/src/shared/utils/browser/set-auth-cookie.ts +++ /dev/null @@ -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: "/", - }); -} From d0decf6a29debb103efbe7bbfac6bf24d1d87f91 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 2 Nov 2023 15:11:10 -0400 Subject: [PATCH 2/3] Revert "Use `auth` cookie set by backend instead of `jwt` (fixes #2193)" This reverts commit 442766c1d813950d178dceda317466bc3c581bee. --- src/shared/config.ts | 2 +- src/shared/services/UserService.ts | 7 +++---- src/shared/utils/browser/clear-auth-cookie.ts | 10 ++++++++++ src/shared/utils/browser/index.ts | 4 ++++ src/shared/utils/browser/set-auth-cookie.ts | 12 ++++++++++++ 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 src/shared/utils/browser/clear-auth-cookie.ts create mode 100644 src/shared/utils/browser/set-auth-cookie.ts diff --git a/src/shared/config.ts b/src/shared/config.ts index 6718de0a7..70019742a 100644 --- a/src/shared/config.ts +++ b/src/shared/config.ts @@ -26,7 +26,7 @@ export const updateUnreadCountsInterval = 30000; export const fetchLimit = 20; export const relTags = "noopener nofollow"; export const emDash = "\u2014"; -export const authCookieName = "auth"; +export const authCookieName = "jwt"; // No. of max displayed communities per // page on route "/communities" diff --git a/src/shared/services/UserService.ts b/src/shared/services/UserService.ts index e5d1afa84..3e459a1ac 100644 --- a/src/shared/services/UserService.ts +++ b/src/shared/services/UserService.ts @@ -1,5 +1,5 @@ import { isAuthPath } from "@utils/app"; -import { isBrowser } from "@utils/browser"; +import { clearAuthCookie, isBrowser, setAuthCookie } from "@utils/browser"; import * as cookie from "cookie"; import jwt_decode from "jwt-decode"; import { LoginResponse, MyUserInfo } from "lemmy-js-client"; @@ -40,6 +40,7 @@ export class UserService { if (isBrowser() && res.jwt) { showToast && toast(I18NextService.i18n.t("logged_in")); + setAuthCookie(res.jwt); this.#setJwtInfo(); } } @@ -49,9 +50,7 @@ export class UserService { this.myUserInfo = undefined; if (isBrowser()) { - // TODO: call logout here - // https://github.com/LemmyNet/lemmy-js-client/pull/208 - //HttpService.client.logout() + clearAuthCookie(); } if (isAuthPath(location.pathname)) { diff --git a/src/shared/utils/browser/clear-auth-cookie.ts b/src/shared/utils/browser/clear-auth-cookie.ts new file mode 100644 index 000000000..f5cc73f13 --- /dev/null +++ b/src/shared/utils/browser/clear-auth-cookie.ts @@ -0,0 +1,10 @@ +import * as cookie from "cookie"; +import { authCookieName } from "../../config"; + +export default function clearAuthCookie() { + document.cookie = cookie.serialize(authCookieName, "", { + maxAge: -1, + sameSite: true, + path: "/", + }); +} diff --git a/src/shared/utils/browser/index.ts b/src/shared/utils/browser/index.ts index a35a81fee..41701207e 100644 --- a/src/shared/utils/browser/index.ts +++ b/src/shared/utils/browser/index.ts @@ -1,4 +1,5 @@ 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"; @@ -6,10 +7,12 @@ 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, @@ -17,5 +20,6 @@ export { platform, restoreScrollPosition, saveScrollPosition, + setAuthCookie, share, }; diff --git a/src/shared/utils/browser/set-auth-cookie.ts b/src/shared/utils/browser/set-auth-cookie.ts new file mode 100644 index 000000000..e7d4300ca --- /dev/null +++ b/src/shared/utils/browser/set-auth-cookie.ts @@ -0,0 +1,12 @@ +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: "/", + }); +} From 3876ad74d1ad0ca78ffc9218521b6147c506a4b6 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 2 Nov 2023 15:44:38 -0400 Subject: [PATCH 3/3] Updating for new lemmy-js-client. --- lemmy-translations | 2 +- package.json | 2 +- .../components/comment/comment-report.tsx | 1 + src/shared/components/community/community.tsx | 13 +++------- src/shared/components/home/admin-settings.tsx | 2 +- src/shared/components/home/home.tsx | 13 +++------- src/shared/components/person/inbox.tsx | 4 ++-- .../components/person/password-change.tsx | 10 ++++---- src/shared/components/person/profile.tsx | 13 +++------- src/shared/components/person/settings.tsx | 15 +++--------- src/shared/components/person/verify-email.tsx | 4 ++-- src/shared/components/post/post-report.tsx | 1 + src/shared/components/post/post.tsx | 24 ++++--------------- src/shared/components/search.tsx | 4 ++-- src/shared/services/UserService.ts | 5 ++-- yarn.lock | 8 +++---- 16 files changed, 38 insertions(+), 83 deletions(-) diff --git a/lemmy-translations b/lemmy-translations index 6b373bf76..abd40d473 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit 6b373bf7665ed58a81d8285009ad147248acfd7c +Subproject commit abd40d4737fa732321fd7b62e42bbfcd51081cb6 diff --git a/package.json b/package.json index 0ec4c20a5..0a3d97440 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "inferno-router": "^8.2.2", "inferno-server": "^8.2.2", "jwt-decode": "^3.1.2", - "lemmy-js-client": "0.19.0-rc.14", + "lemmy-js-client": "0.19.0-alpha.16", "lodash.isequal": "^4.5.0", "markdown-it": "^13.0.1", "markdown-it-bidi": "^0.1.0", diff --git a/src/shared/components/comment/comment-report.tsx b/src/shared/components/comment/comment-report.tsx index d5d0bba73..8d2e04018 100644 --- a/src/shared/components/comment/comment-report.tsx +++ b/src/shared/components/comment/comment-report.tsx @@ -56,6 +56,7 @@ export class CommentReport extends Component< post: r.post, community: r.community, creator_banned_from_community: r.creator_banned_from_community, + creator_is_moderator: false, counts: r.counts, subscribed: "NotSubscribed", saved: false, diff --git a/src/shared/components/community/community.tsx b/src/shared/components/community/community.tsx index 8f3c0bb57..021214b41 100644 --- a/src/shared/components/community/community.tsx +++ b/src/shared/components/community/community.tsx @@ -57,12 +57,10 @@ import { LockPost, MarkCommentReplyAsRead, MarkPersonMentionAsRead, - MarkPostAsRead, PaginationCursor, PostResponse, PurgeComment, PurgeCommunity, - PurgeItemResponse, PurgePerson, PurgePost, RemoveComment, @@ -71,6 +69,7 @@ import { SaveComment, SavePost, SortType, + SuccessResponse, TransferCommunity, } from "lemmy-js-client"; import { fetchLimit, relTags } from "../../config"; @@ -198,7 +197,6 @@ export class Community extends Component< this.handleSavePost = this.handleSavePost.bind(this); this.handlePurgePost = this.handlePurgePost.bind(this); this.handleFeaturePost = this.handleFeaturePost.bind(this); - this.handleMarkPostAsRead = this.handleMarkPostAsRead.bind(this); this.mainContentRef = createRef(); // Only fetch the data if coming from another route if (FirstLoadService.isFirstLoad) { @@ -436,7 +434,7 @@ export class Community extends Component< onAddAdmin={this.handleAddAdmin} onTransferCommunity={this.handleTransferCommunity} onFeaturePost={this.handleFeaturePost} - onMarkPostAsRead={this.handleMarkPostAsRead} + onMarkPostAsRead={() => {}} /> ); } @@ -804,11 +802,6 @@ export class Community extends Component< await HttpService.client.markPersonMentionAsRead(form); } - async handleMarkPostAsRead(form: MarkPostAsRead) { - const res = await HttpService.client.markPostAsRead(form); - this.findAndUpdatePost(res); - } - async handleBanFromCommunity(form: BanFromCommunity) { const banRes = await HttpService.client.banFromCommunity(form); this.updateBanFromCommunity(banRes); @@ -882,7 +875,7 @@ export class Community extends Component< }); } - purgeItem(purgeRes: RequestState) { + purgeItem(purgeRes: RequestState) { if (purgeRes.state === "success") { toast(I18NextService.i18n.t("purge_success")); this.context.router.history.push(`/`); diff --git a/src/shared/components/home/admin-settings.tsx b/src/shared/components/home/admin-settings.tsx index a799b455f..26a49fe2b 100644 --- a/src/shared/components/home/admin-settings.tsx +++ b/src/shared/components/home/admin-settings.tsx @@ -359,7 +359,7 @@ export class AdminSettings extends Component { async handleDeleteEmoji(form: DeleteCustomEmoji) { const res = await HttpService.client.deleteCustomEmoji(form); if (res.state === "success") { - removeFromEmojiDataModel(res.data.id); + removeFromEmojiDataModel(form.id); } } diff --git a/src/shared/components/home/home.tsx b/src/shared/components/home/home.tsx index 257f46c73..cac283ab8 100644 --- a/src/shared/components/home/home.tsx +++ b/src/shared/components/home/home.tsx @@ -58,11 +58,9 @@ import { LockPost, MarkCommentReplyAsRead, MarkPersonMentionAsRead, - MarkPostAsRead, PaginationCursor, PostResponse, PurgeComment, - PurgeItemResponse, PurgePerson, PurgePost, RemoveComment, @@ -70,6 +68,7 @@ import { SaveComment, SavePost, SortType, + SuccessResponse, TransferCommunity, } from "lemmy-js-client"; import { fetchLimit, relTags, trendingFetchLimit } from "../../config"; @@ -276,7 +275,6 @@ export class Home extends Component { this.handleSavePost = this.handleSavePost.bind(this); this.handlePurgePost = this.handlePurgePost.bind(this); this.handleFeaturePost = this.handleFeaturePost.bind(this); - this.handleMarkPostAsRead = this.handleMarkPostAsRead.bind(this); // Only fetch the data if coming from another route if (FirstLoadService.isFirstLoad) { @@ -713,7 +711,7 @@ export class Home extends Component { onAddAdmin={this.handleAddAdmin} onTransferCommunity={this.handleTransferCommunity} onFeaturePost={this.handleFeaturePost} - onMarkPostAsRead={this.handleMarkPostAsRead} + onMarkPostAsRead={() => {}} /> ); } @@ -1043,11 +1041,6 @@ export class Home extends Component { this.updateBan(banRes); } - async handleMarkPostAsRead(form: MarkPostAsRead) { - const res = await HttpService.client.markPostAsRead(form); - this.findAndUpdatePost(res); - } - updateBanFromCommunity(banRes: RequestState) { // Maybe not necessary if (banRes.state === "success") { @@ -1090,7 +1083,7 @@ export class Home extends Component { } } - purgeItem(purgeRes: RequestState) { + purgeItem(purgeRes: RequestState) { if (purgeRes.state === "success") { toast(I18NextService.i18n.t("purge_success")); this.context.router.history.push(`/`); diff --git a/src/shared/components/person/inbox.tsx b/src/shared/components/person/inbox.tsx index d1237e7b8..02b3b63d9 100644 --- a/src/shared/components/person/inbox.tsx +++ b/src/shared/components/person/inbox.tsx @@ -52,11 +52,11 @@ import { PrivateMessageView, PrivateMessagesResponse, PurgeComment, - PurgeItemResponse, PurgePerson, PurgePost, RemoveComment, SaveComment, + SuccessResponse, TransferCommunity, } from "lemmy-js-client"; import { fetchLimit, relTags } from "../../config"; @@ -1038,7 +1038,7 @@ export class Inbox extends Component { } } - purgeItem(purgeRes: RequestState) { + purgeItem(purgeRes: RequestState) { if (purgeRes.state === "success") { toast(I18NextService.i18n.t("purge_success")); this.context.router.history.push(`/`); diff --git a/src/shared/components/person/password-change.tsx b/src/shared/components/person/password-change.tsx index 8fc8078d0..2d3d3df2e 100644 --- a/src/shared/components/person/password-change.tsx +++ b/src/shared/components/person/password-change.tsx @@ -1,7 +1,7 @@ import { setIsoData } from "@utils/app"; import { capitalizeFirstLetter } from "@utils/helpers"; import { Component, linkEvent } from "inferno"; -import { GetSiteResponse, LoginResponse } from "lemmy-js-client"; +import { GetSiteResponse, SuccessResponse } from "lemmy-js-client"; import { HttpService, I18NextService, UserService } from "../../services"; import { EMPTY_REQUEST, @@ -11,9 +11,10 @@ import { import { HtmlTags } from "../common/html-tags"; import { Spinner } from "../common/icon"; import PasswordInput from "../common/password-input"; +import { toast } from "../../toast"; interface State { - passwordChangeRes: RequestState; + passwordChangeRes: RequestState; form: { token: string; password?: string; @@ -125,10 +126,7 @@ export class PasswordChange extends Component { }); if (i.state.passwordChangeRes.state === "success") { - const data = i.state.passwordChangeRes.data; - UserService.Instance.login({ - res: data, - }); + toast(I18NextService.i18n.t("password_changed")); const site = await HttpService.client.getSite(); if (site.state === "success") { diff --git a/src/shared/components/person/profile.tsx b/src/shared/components/person/profile.tsx index 37477105d..d1e813cc7 100644 --- a/src/shared/components/person/profile.tsx +++ b/src/shared/components/person/profile.tsx @@ -58,11 +58,9 @@ import { LockPost, MarkCommentReplyAsRead, MarkPersonMentionAsRead, - MarkPostAsRead, PersonView, PostResponse, PurgeComment, - PurgeItemResponse, PurgePerson, PurgePost, RemoveComment, @@ -70,6 +68,7 @@ import { SaveComment, SavePost, SortType, + SuccessResponse, TransferCommunity, } from "lemmy-js-client"; import { fetchLimit, relTags } from "../../config"; @@ -222,7 +221,6 @@ export class Profile extends Component< this.handlePurgePost = this.handlePurgePost.bind(this); this.handleFeaturePost = this.handleFeaturePost.bind(this); this.handleModBanSubmit = this.handleModBanSubmit.bind(this); - this.handleMarkPostAsRead = this.handleMarkPostAsRead.bind(this); // Only fetch the data if coming from another route if (FirstLoadService.isFirstLoad) { @@ -378,7 +376,7 @@ export class Profile extends Component< onSavePost={this.handleSavePost} onPurgePost={this.handlePurgePost} onFeaturePost={this.handleFeaturePost} - onMarkPostAsRead={this.handleMarkPostAsRead} + onMarkPostAsRead={() => {}} /> @@ -947,11 +945,6 @@ export class Profile extends Component< await HttpService.client.markPersonMentionAsRead(form); } - async handleMarkPostAsRead(form: MarkPostAsRead) { - const res = await HttpService.client.markPostAsRead(form); - this.findAndUpdatePost(res); - } - async handleBanFromCommunity(form: BanFromCommunity) { const banRes = await HttpService.client.banFromCommunity(form); this.updateBanFromCommunity(banRes); @@ -1002,7 +995,7 @@ export class Profile extends Component< } } - purgeItem(purgeRes: RequestState) { + purgeItem(purgeRes: RequestState) { if (purgeRes.state === "success") { toast(I18NextService.i18n.t("purge_success")); this.context.router.history.push(`/`); diff --git a/src/shared/components/person/settings.tsx b/src/shared/components/person/settings.tsx index 2e74aa09b..c7dabb982 100644 --- a/src/shared/components/person/settings.tsx +++ b/src/shared/components/person/settings.tsx @@ -23,7 +23,6 @@ import { BlockInstanceResponse, BlockPersonResponse, CommunityBlockView, - DeleteAccountResponse, GenerateTotpSecretResponse, GetFederatedInstancesResponse, GetSiteResponse, @@ -33,6 +32,7 @@ import { LoginResponse, PersonBlockView, SortType, + SuccessResponse, UpdateTotpResponse, } from "lemmy-js-client"; import { elementUrl, emDash, relTags } from "../../config"; @@ -66,9 +66,9 @@ type SettingsData = RouteDataResponse<{ }>; interface SettingsState { - saveRes: RequestState; + saveRes: RequestState; changePasswordRes: RequestState; - deleteAccountRes: RequestState; + deleteAccountRes: RequestState; instancesRes: RequestState; generateTotpRes: RequestState; updateTotpRes: RequestState; @@ -1436,11 +1436,6 @@ export class Settings extends Component { }); if (saveRes.state === "success") { - UserService.Instance.login({ - res: saveRes.data, - showToast: false, - }); - const siteRes = await HttpService.client.getSite(); if (siteRes.state === "success") { @@ -1471,10 +1466,6 @@ export class Settings extends Component { old_password, }); if (changePasswordRes.state === "success") { - UserService.Instance.login({ - res: changePasswordRes.data, - showToast: false, - }); window.scrollTo(0, 0); toast(I18NextService.i18n.t("password_changed")); } diff --git a/src/shared/components/person/verify-email.tsx b/src/shared/components/person/verify-email.tsx index 35bece5ff..e8f116c48 100644 --- a/src/shared/components/person/verify-email.tsx +++ b/src/shared/components/person/verify-email.tsx @@ -1,6 +1,6 @@ import { setIsoData } from "@utils/app"; import { Component } from "inferno"; -import { GetSiteResponse, VerifyEmailResponse } from "lemmy-js-client"; +import { GetSiteResponse, SuccessResponse } from "lemmy-js-client"; import { I18NextService } from "../../services"; import { EMPTY_REQUEST, @@ -13,7 +13,7 @@ import { HtmlTags } from "../common/html-tags"; import { Spinner } from "../common/icon"; interface State { - verifyRes: RequestState; + verifyRes: RequestState; siteRes: GetSiteResponse; } diff --git a/src/shared/components/post/post-report.tsx b/src/shared/components/post/post-report.tsx index ea3b68cfb..a215e646b 100644 --- a/src/shared/components/post/post-report.tsx +++ b/src/shared/components/post/post-report.tsx @@ -56,6 +56,7 @@ export class PostReport extends Component { creator_blocked: false, my_vote: r.my_vote, unread_comments: 0, + creator_is_moderator: false, }; return ( diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx index 519bff48c..73fcfb6ac 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -61,12 +61,9 @@ import { GetSiteResponse, LockPost, MarkCommentReplyAsRead, - MarkPersonMentionAsRead, - MarkPostAsRead, PostResponse, PurgeComment, PurgeCommunity, - PurgeItemResponse, PurgePerson, PurgePost, RemoveComment, @@ -74,6 +71,7 @@ import { RemovePost, SaveComment, SavePost, + SuccessResponse, TransferCommunity, } from "lemmy-js-client"; import { commentTreeMaxDepth } from "../../config"; @@ -164,7 +162,6 @@ export class Post extends Component { this.handleTransferCommunity = this.handleTransferCommunity.bind(this); this.handleFetchChildren = this.handleFetchChildren.bind(this); this.handleCommentReplyRead = this.handleCommentReplyRead.bind(this); - this.handlePersonMentionRead = this.handlePersonMentionRead.bind(this); this.handleBanFromCommunity = this.handleBanFromCommunity.bind(this); this.handleBanPerson = this.handleBanPerson.bind(this); this.handlePostEdit = this.handlePostEdit.bind(this); @@ -176,7 +173,6 @@ export class Post extends Component { this.handleSavePost = this.handleSavePost.bind(this); this.handlePurgePost = this.handlePurgePost.bind(this); this.handleFeaturePost = this.handleFeaturePost.bind(this); - this.handleMarkPostAsRead = this.handleMarkPostAsRead.bind(this); this.state = { ...this.state, commentSectionRef: createRef() }; @@ -387,7 +383,7 @@ export class Post extends Component { onAddAdmin={this.handleAddAdmin} onTransferCommunity={this.handleTransferCommunity} onFeaturePost={this.handleFeaturePost} - onMarkPostAsRead={this.handleMarkPostAsRead} + onMarkPostAsRead={() => {}} />
@@ -589,7 +585,7 @@ export class Post extends Component { onPurgeComment={this.handlePurgeComment} onPurgePerson={this.handlePurgePerson} onCommentReplyRead={this.handleCommentReplyRead} - onPersonMentionRead={this.handlePersonMentionRead} + onPersonMentionRead={() => {}} onBanPersonFromCommunity={this.handleBanFromCommunity} onBanPerson={this.handleBanPerson} onCreateComment={this.handleCreateComment} @@ -676,7 +672,7 @@ export class Post extends Component { onPurgeComment={this.handlePurgeComment} onPurgePerson={this.handlePurgePerson} onCommentReplyRead={this.handleCommentReplyRead} - onPersonMentionRead={this.handlePersonMentionRead} + onPersonMentionRead={() => {}} onBanPersonFromCommunity={this.handleBanFromCommunity} onBanPerson={this.handleBanPerson} onCreateComment={this.handleCreateComment} @@ -936,16 +932,6 @@ export class Post extends Component { this.findAndUpdateCommentReply(readRes); } - async handlePersonMentionRead(form: MarkPersonMentionAsRead) { - // TODO not sure what to do here. Maybe it is actually optional, because post doesn't need it. - await HttpService.client.markPersonMentionAsRead(form); - } - - async handleMarkPostAsRead(form: MarkPostAsRead) { - const res = await HttpService.client.markPostAsRead(form); - this.updatePost(res); - } - async handleBanFromCommunity(form: BanFromCommunity) { const banRes = await HttpService.client.banFromCommunity(form); this.updateBan(banRes); @@ -1029,7 +1015,7 @@ export class Post extends Component { }); } - purgeItem(purgeRes: RequestState) { + purgeItem(purgeRes: RequestState) { if (purgeRes.state === "success") { toast(I18NextService.i18n.t("purge_success")); this.context.router.history.push(`/`); diff --git a/src/shared/components/search.tsx b/src/shared/components/search.tsx index 46bb51198..2b90da51f 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -665,10 +665,10 @@ export class Search extends Component { Number( ((b.data as CommentView | PostView).counts.score | (b.data as CommunityView).counts.subscribers | - (b.data as PersonView).counts.comment_score) - + (b.data as PersonView).counts.comment_count) - ((a.data as CommentView | PostView).counts.score | (a.data as CommunityView).counts.subscribers | - (a.data as PersonView).counts.comment_score), + (a.data as PersonView).counts.comment_count), ), ); } diff --git a/src/shared/services/UserService.ts b/src/shared/services/UserService.ts index 3e459a1ac..c53ca1fae 100644 --- a/src/shared/services/UserService.ts +++ b/src/shared/services/UserService.ts @@ -35,9 +35,6 @@ export class UserService { res: LoginResponse; showToast?: boolean; }) { - const expires = new Date(); - expires.setDate(expires.getDate() + 365); - if (isBrowser() && res.jwt) { showToast && toast(I18NextService.i18n.t("logged_in")); setAuthCookie(res.jwt); @@ -53,6 +50,8 @@ export class UserService { clearAuthCookie(); } + HttpService.client.logout(); + if (isAuthPath(location.pathname)) { location.replace("/"); } else { diff --git a/yarn.lock b/yarn.lock index 6e2b5c79a..ec0f69886 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6069,10 +6069,10 @@ leac@^0.6.0: resolved "https://registry.yarnpkg.com/leac/-/leac-0.6.0.tgz#dcf136e382e666bd2475f44a1096061b70dc0912" integrity sha512-y+SqErxb8h7nE/fiEX07jsbuhrpO9lL8eca7/Y1nuWV2moNlXhyd59iDGcRf6moVyDMbmTNzL40SUyrFU/yDpg== -lemmy-js-client@0.19.0-rc.14: - version "0.19.0-rc.14" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.19.0-rc.14.tgz#41885611c2d78e5cb6b01cf167d68205a471c215" - integrity sha512-U0KKFLrU0K+A7UlZr+k4olrXCXBxD+9cwMicu7L/wFyZ2aWHtGPaeO8V6mk6suv9vn2w2PWuimIIC+YICQ5xKg== +lemmy-js-client@0.19.0-alpha.16: + version "0.19.0-alpha.16" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.19.0-alpha.16.tgz#4ec26e393856db7ddf86dba83f24633eeacee7c4" + integrity sha512-pmfrkPrHBkhEFhw/BDiTPy2/aQLoURLwBftMa4Lc+ZYiRfVClCOPkbKiqDSYXYlWcPz5MtwM/bjSNxasvVHfTA== dependencies: cross-fetch "^3.1.5" form-data "^4.0.0"