diff --git a/package.json b/package.json index 92e0c1b0..cbba7314 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "inferno-router": "^8.2.2", "inferno-server": "^8.2.2", "jwt-decode": "^3.1.2", - "lemmy-js-client": "^0.19.0-rc.7", + "lemmy-js-client": "^0.19.0-rc.12", "lodash.isequal": "^4.5.0", "markdown-it": "^13.0.1", "markdown-it-container": "^3.0.0", diff --git a/src/server/handlers/catch-all-handler.tsx b/src/server/handlers/catch-all-handler.tsx index d3cf39ff..6e93a1ae 100644 --- a/src/server/handlers/catch-all-handler.tsx +++ b/src/server/handlers/catch-all-handler.tsx @@ -6,7 +6,7 @@ import fetch from "cross-fetch"; import type { Request, Response } from "express"; import { StaticRouter, matchPath } from "inferno-router"; import { renderToString } from "inferno-server"; -import { GetSite, GetSiteResponse, LemmyHttp } from "lemmy-js-client"; +import { GetSiteResponse, LemmyHttp } from "lemmy-js-client"; import { App } from "../../shared/components/app/app"; import { InitialFetchRequest, @@ -26,18 +26,19 @@ export default async (req: Request, res: Response) => { try { const activeRoute = routes.find(route => matchPath(req.path, route)); - let auth = req.headers.cookie - ? cookie.parse(req.headers.cookie).jwt - : undefined; - - const getSiteForm: GetSite = { auth }; - const headers = setForwardedHeaders(req.headers); const client = wrapClient( new LemmyHttp(getHttpBaseInternal(), { fetchFunction: fetch, headers }), ); + const auth = req.headers.cookie + ? cookie.parse(req.headers.cookie).jwt + : undefined; + + if (auth) { + client.setHeaders({ Authorization: `Bearer ${auth}` }); + } const { path, url, query } = req; // Get site data first @@ -46,15 +47,14 @@ export default async (req: Request, res: Response) => { let site: GetSiteResponse | undefined = undefined; let routeData: RouteData = {}; let errorPageData: ErrorPageData | undefined = undefined; - let try_site = await client.getSite(getSiteForm); + let try_site = await client.getSite(); if (try_site.state === "failed" && try_site.msg === "not_logged_in") { console.error( "Incorrect JWT token, skipping auth so frontend can remove jwt cookie", ); - getSiteForm.auth = undefined; - auth = undefined; - try_site = await client.getSite(getSiteForm); + client.setHeaders({}); + try_site = await client.getSite(); } if (!auth && isAuthPath(path)) { @@ -72,7 +72,6 @@ export default async (req: Request, res: Response) => { if (site && activeRoute?.fetchInitialData) { const initialFetchReq: InitialFetchRequest = { client, - auth, path, query, site, diff --git a/src/server/handlers/manifest-handler.ts b/src/server/handlers/manifest-handler.ts index 2cbb64f5..dfc1ad8e 100644 --- a/src/server/handlers/manifest-handler.ts +++ b/src/server/handlers/manifest-handler.ts @@ -15,7 +15,7 @@ export default async (req: Request, res: Response) => { const client = wrapClient( new LemmyHttp(getHttpBaseInternal(), { fetchFunction: fetch, headers }), ); - const site = await client.getSite({}); + const site = await client.getSite(); if (site.state === "success") { manifest = await generateManifestJson(site.data); diff --git a/src/shared/components/app/error-page.tsx b/src/shared/components/app/error-page.tsx index e083276e..a0b8d535 100644 --- a/src/shared/components/app/error-page.tsx +++ b/src/shared/components/app/error-page.tsx @@ -1,5 +1,4 @@ import { setIsoData } from "@utils/app"; -import { removeAuthParam } from "@utils/helpers"; import { Component } from "inferno"; import { T } from "inferno-i18next-dess"; import { Link } from "inferno-router"; @@ -56,11 +55,7 @@ export class ErrorPage extends Component { )} {errorPageData?.error && ( - + ### )} diff --git a/src/shared/components/app/navbar.tsx b/src/shared/components/app/navbar.tsx index 0e96d680..3c3b2725 100644 --- a/src/shared/components/app/navbar.tsx +++ b/src/shared/components/app/navbar.tsx @@ -450,28 +450,21 @@ export class Navbar extends Component { fetchUnreads() { poll(async () => { if (window.document.visibilityState !== "hidden") { - const auth = myAuth(); - if (auth) { + if (myAuth()) { this.setState({ - unreadInboxCountRes: await HttpService.client.getUnreadCount({ - auth, - }), + unreadInboxCountRes: await HttpService.client.getUnreadCount(), }); if (this.moderatesSomething) { this.setState({ - unreadReportCountRes: await HttpService.client.getReportCount({ - auth, - }), + unreadReportCountRes: await HttpService.client.getReportCount({}), }); } if (amAdmin()) { this.setState({ unreadApplicationCountRes: - await HttpService.client.getUnreadRegistrationApplicationCount({ - auth, - }), + await HttpService.client.getUnreadRegistrationApplicationCount(), }); } } diff --git a/src/shared/components/comment/comment-form.tsx b/src/shared/components/comment/comment-form.tsx index 32c687c2..86830740 100644 --- a/src/shared/components/comment/comment-form.tsx +++ b/src/shared/components/comment/comment-form.tsx @@ -1,4 +1,3 @@ -import { myAuthRequired } from "@utils/app"; import { capitalizeFirstLetter } from "@utils/helpers"; import { Component } from "inferno"; import { T } from "inferno-i18next-dess"; @@ -92,7 +91,6 @@ export class CommentForm extends Component { content, post_id, language_id, - auth: myAuthRequired(), }); } else { if (edit) { @@ -101,7 +99,6 @@ export class CommentForm extends Component { content, comment_id, language_id, - auth: myAuthRequired(), }); } else { const post_id = node.comment_view.post.id; @@ -111,7 +108,6 @@ export class CommentForm extends Component { parent_id, post_id, language_id, - auth: myAuthRequired(), }); } } diff --git a/src/shared/components/comment/comment-node.tsx b/src/shared/components/comment/comment-node.tsx index 8f723ae9..aabe9a91 100644 --- a/src/shared/components/comment/comment-node.tsx +++ b/src/shared/components/comment/comment-node.tsx @@ -1,10 +1,4 @@ -import { - colorList, - getCommentParentId, - myAuth, - myAuthRequired, - showScores, -} from "@utils/app"; +import { colorList, getCommentParentId, showScores } from "@utils/app"; import { futureDaysToUnixTime, numToSI } from "@utils/helpers"; import { amCommunityCreator, @@ -1380,7 +1374,6 @@ export class CommentNode extends Component { i.props.onSaveComment({ comment_id: i.commentView.comment.id, save: !i.commentView.saved, - auth: myAuthRequired(), }); } @@ -1389,7 +1382,6 @@ export class CommentNode extends Component { i.props.onBlockPerson({ person_id: i.commentView.creator.id, block: true, - auth: myAuthRequired(), }); } @@ -1400,13 +1392,11 @@ export class CommentNode extends Component { i.props.onPersonMentionRead({ person_mention_id: cv.person_mention.id, read: !cv.person_mention.read, - auth: myAuthRequired(), }); } else if (i.isCommentReplyType(cv)) { i.props.onCommentReplyRead({ comment_reply_id: cv.comment_reply.id, read: !cv.comment_reply.read, - auth: myAuthRequired(), }); } } @@ -1416,7 +1406,6 @@ export class CommentNode extends Component { i.props.onDeleteComment({ comment_id: i.commentId, deleted: !i.commentView.comment.deleted, - auth: myAuthRequired(), }); } @@ -1426,7 +1415,6 @@ export class CommentNode extends Component { i.props.onRemoveComment({ comment_id: i.commentId, removed: !i.commentView.comment.removed, - auth: myAuthRequired(), reason: i.state.removeReason, }); } @@ -1436,7 +1424,6 @@ export class CommentNode extends Component { i.props.onDistinguishComment({ comment_id: i.commentId, distinguished: !i.commentView.comment.distinguished, - auth: myAuthRequired(), }); } @@ -1449,7 +1436,6 @@ export class CommentNode extends Component { reason: i.state.banReason, remove_data: i.state.removeData, expires: futureDaysToUnixTime(i.state.banExpireDays), - auth: myAuthRequired(), }); } @@ -1461,7 +1447,6 @@ export class CommentNode extends Component { reason: i.state.banReason, remove_data: i.state.removeData, expires: futureDaysToUnixTime(i.state.banExpireDays), - auth: myAuthRequired(), }); } @@ -1482,7 +1467,6 @@ export class CommentNode extends Component { community_id: i.commentView.community.id, person_id: i.commentView.creator.id, added, - auth: myAuthRequired(), }); } @@ -1493,7 +1477,6 @@ export class CommentNode extends Component { i.props.onAddAdmin({ person_id: i.commentView.creator.id, added, - auth: myAuthRequired(), }); } @@ -1502,7 +1485,6 @@ export class CommentNode extends Component { i.props.onTransferCommunity({ community_id: i.commentView.community.id, person_id: i.commentView.creator.id, - auth: myAuthRequired(), }); } @@ -1510,7 +1492,6 @@ export class CommentNode extends Component { this.props.onCommentReport({ comment_id: this.commentId, reason, - auth: myAuthRequired(), }); this.setState({ @@ -1526,13 +1507,11 @@ export class CommentNode extends Component { i.props.onPurgePerson({ person_id: i.commentView.creator.id, reason: i.state.purgeReason, - auth: myAuthRequired(), }); } else { i.props.onPurgeComment({ comment_id: i.commentId, reason: i.state.purgeReason, - auth: myAuthRequired(), }); } } @@ -1545,7 +1524,6 @@ export class CommentNode extends Component { limit: 999, // TODO type_: "All", saved_only: false, - auth: myAuth(), }); } } diff --git a/src/shared/components/comment/comment-report.tsx b/src/shared/components/comment/comment-report.tsx index 834f96a4..ff740b59 100644 --- a/src/shared/components/comment/comment-report.tsx +++ b/src/shared/components/comment/comment-report.tsx @@ -1,4 +1,3 @@ -import { myAuthRequired } from "@utils/app"; import { Component, InfernoNode, linkEvent } from "inferno"; import { T } from "inferno-i18next-dess"; import { @@ -149,7 +148,6 @@ export class CommentReport extends Component< i.props.onResolveReport({ report_id: i.props.report.comment_report.id, resolved: !i.props.report.comment_report.resolved, - auth: myAuthRequired(), }); } } diff --git a/src/shared/components/common/registration-application.tsx b/src/shared/components/common/registration-application.tsx index 6afe8cab..cc3a123e 100644 --- a/src/shared/components/common/registration-application.tsx +++ b/src/shared/components/common/registration-application.tsx @@ -1,4 +1,3 @@ -import { myAuthRequired } from "@utils/app"; import { Component, InfernoNode, linkEvent } from "inferno"; import { T } from "inferno-i18next-dess"; import { @@ -149,7 +148,6 @@ export class RegistrationApplication extends Component< i.props.onApproveApplication({ id: i.props.application.registration_application.id, approve: true, - auth: myAuthRequired(), }); } @@ -160,7 +158,6 @@ export class RegistrationApplication extends Component< id: i.props.application.registration_application.id, approve: false, deny_reason: i.state.denyReason, - auth: myAuthRequired(), }); } else { i.setState({ denyExpanded: true }); diff --git a/src/shared/components/common/vote-buttons.tsx b/src/shared/components/common/vote-buttons.tsx index 8a89a2c3..91e8156c 100644 --- a/src/shared/components/common/vote-buttons.tsx +++ b/src/shared/components/common/vote-buttons.tsx @@ -1,4 +1,4 @@ -import { myAuthRequired, newVote, showScores } from "@utils/app"; +import { newVote, showScores } from "@utils/app"; import { numToSI } from "@utils/helpers"; import classNames from "classnames"; import { Component, linkEvent } from "inferno"; @@ -53,7 +53,6 @@ const handleUpvote = (i: VoteButtons) => { i.props.onVote({ comment_id: i.props.id, score: newVote(VoteType.Upvote, i.props.my_vote), - auth: myAuthRequired(), }); break; case VoteContentType.Post: @@ -61,7 +60,6 @@ const handleUpvote = (i: VoteButtons) => { i.props.onVote({ post_id: i.props.id, score: newVote(VoteType.Upvote, i.props.my_vote), - auth: myAuthRequired(), }); } }; @@ -73,7 +71,6 @@ const handleDownvote = (i: VoteButtons) => { i.props.onVote({ comment_id: i.props.id, score: newVote(VoteType.Downvote, i.props.my_vote), - auth: myAuthRequired(), }); break; case VoteContentType.Post: @@ -81,7 +78,6 @@ const handleDownvote = (i: VoteButtons) => { i.props.onVote({ post_id: i.props.id, score: newVote(VoteType.Downvote, i.props.my_vote), - auth: myAuthRequired(), }); } }; diff --git a/src/shared/components/community/communities.tsx b/src/shared/components/community/communities.tsx index 9222df82..5c04b70a 100644 --- a/src/shared/components/community/communities.tsx +++ b/src/shared/components/community/communities.tsx @@ -1,10 +1,4 @@ -import { - editCommunity, - myAuth, - myAuthRequired, - setIsoData, - showLocal, -} from "@utils/app"; +import { editCommunity, setIsoData, showLocal } from "@utils/app"; import { getPageFromString, getQueryParams, @@ -308,7 +302,6 @@ export class Communities extends Component { static async fetchInitialData({ query: { listingType, sort, page }, client, - auth, }: InitialFetchRequest< QueryParams >): Promise { @@ -317,7 +310,6 @@ export class Communities extends Component { sort: getSortTypeFromQuery(sort), limit: communityLimit, page: getPageFromString(page), - auth: auth, }; return { @@ -335,7 +327,6 @@ export class Communities extends Component { const res = await HttpService.client.followCommunity({ community_id: data.communityId, follow: data.follow, - auth: myAuthRequired(), }); data.i.findAndUpdateCommunity(res); } @@ -351,7 +342,6 @@ export class Communities extends Component { sort: sort, limit: communityLimit, page, - auth: myAuth(), }), }); diff --git a/src/shared/components/community/community-form.tsx b/src/shared/components/community/community-form.tsx index e44675c9..ec0ded36 100644 --- a/src/shared/components/community/community-form.tsx +++ b/src/shared/components/community/community-form.tsx @@ -1,4 +1,3 @@ -import { myAuthRequired } from "@utils/app"; import { capitalizeFirstLetter, randomStr } from "@utils/helpers"; import { Component, linkEvent } from "inferno"; import { Prompt } from "inferno-router"; @@ -279,7 +278,6 @@ export class CommunityForm extends Component< event.preventDefault(); i.setState({ submitted: true }); const cForm = i.state.form; - const auth = myAuthRequired(); const cv = i.props.community_view; @@ -293,7 +291,6 @@ export class CommunityForm extends Component< nsfw: cForm.nsfw, posting_restricted_to_mods: cForm.posting_restricted_to_mods, discussion_languages: cForm.discussion_languages, - auth, }); } else { if (cForm.title && cForm.name) { @@ -306,7 +303,6 @@ export class CommunityForm extends Component< nsfw: cForm.nsfw, posting_restricted_to_mods: cForm.posting_restricted_to_mods, discussion_languages: cForm.discussion_languages, - auth, }); } } diff --git a/src/shared/components/community/community.tsx b/src/shared/components/community/community.tsx index 02d88dfe..6b70b550 100644 --- a/src/shared/components/community/community.tsx +++ b/src/shared/components/community/community.tsx @@ -8,7 +8,6 @@ import { enableNsfw, getCommentParentId, getDataTypeString, - myAuth, postToCommentSortType, setIsoData, showLocal, @@ -217,7 +216,6 @@ export class Community extends Component< this.setState({ communityRes: await HttpService.client.getCommunity({ name: this.props.match.params.name, - auth: myAuth(), }), }); } @@ -234,7 +232,6 @@ export class Community extends Component< client, path, query: { dataType: urlDataType, page: urlPage, sort: urlSort }, - auth, }: InitialFetchRequest>): Promise< Promise > { @@ -243,7 +240,6 @@ export class Community extends Component< const communityName = pathSplit[2]; const communityForm: GetCommunity = { name: communityName, - auth, }; const dataType = getDataTypeFromQuery(urlDataType); @@ -265,7 +261,6 @@ export class Community extends Component< sort, type_: "All", saved_only: false, - auth, }; postsResponse = await client.getPosts(getPostsForm); @@ -277,7 +272,6 @@ export class Community extends Component< sort: postToCommentSortType(sort), type_: "All", saved_only: false, - auth, }; commentsResponse = await client.getComments(getCommentsForm); @@ -600,7 +594,6 @@ export class Community extends Component< type_: "All", community_name: name, saved_only: false, - auth: myAuth(), }), }); } else { @@ -613,7 +606,6 @@ export class Community extends Component< type_: "All", community_name: name, saved_only: false, - auth: myAuth(), }), }); } diff --git a/src/shared/components/community/sidebar.tsx b/src/shared/components/community/sidebar.tsx index 8992c69f..6fd6bfa6 100644 --- a/src/shared/components/community/sidebar.tsx +++ b/src/shared/components/community/sidebar.tsx @@ -1,4 +1,3 @@ -import { myAuthRequired } from "@utils/app"; import { getUnixTime, hostname } from "@utils/helpers"; import { amAdmin, amMod, amTopMod } from "@utils/roles"; import { Component, InfernoNode, linkEvent } from "inferno"; @@ -500,7 +499,6 @@ export class Sidebar extends Component { i.props.onFollowCommunity({ community_id: i.props.community_view.community.id, follow: false, - auth: myAuthRequired(), }); } @@ -509,7 +507,6 @@ export class Sidebar extends Component { i.props.onFollowCommunity({ community_id: i.props.community_view.community.id, follow: true, - auth: myAuthRequired(), }); } @@ -519,7 +516,6 @@ export class Sidebar extends Component { i.props.onBlockCommunity({ community_id: community.id, block: !blocked, - auth: myAuthRequired(), }); } @@ -531,7 +527,6 @@ export class Sidebar extends Component { community_id: i.props.community_view.community.id, person_id: myId, added: false, - auth: myAuthRequired(), }); } } @@ -541,7 +536,6 @@ export class Sidebar extends Component { i.props.onDeleteCommunity({ community_id: i.props.community_view.community.id, deleted: !i.props.community_view.community.deleted, - auth: myAuthRequired(), }); } @@ -553,7 +547,6 @@ export class Sidebar extends Component { removed: !i.props.community_view.community.removed, reason: i.state.removeReason, expires: getUnixTime(i.state.removeExpires), // TODO fix this - auth: myAuthRequired(), }); } @@ -563,7 +556,6 @@ export class Sidebar extends Component { i.props.onPurgeCommunity({ community_id: i.props.community_view.community.id, reason: i.state.purgeReason, - auth: myAuthRequired(), }); } } diff --git a/src/shared/components/home/admin-settings.tsx b/src/shared/components/home/admin-settings.tsx index 4924508f..c86fd01f 100644 --- a/src/shared/components/home/admin-settings.tsx +++ b/src/shared/components/home/admin-settings.tsx @@ -1,9 +1,4 @@ -import { - fetchThemeList, - myAuthRequired, - setIsoData, - showLocal, -} from "@utils/app"; +import { fetchThemeList, setIsoData, showLocal } from "@utils/app"; import { capitalizeFirstLetter } from "@utils/helpers"; import { RouteDataResponse } from "@utils/types"; import classNames from "classnames"; @@ -85,16 +80,11 @@ export class AdminSettings extends Component { } static async fetchInitialData({ - auth, client, }: InitialFetchRequest): Promise { return { - bannedRes: await client.getBannedPersons({ - auth: auth as string, - }), - instancesRes: await client.getFederatedInstances({ - auth: auth as string, - }), + bannedRes: await client.getBannedPersons(), + instancesRes: await client.getFederatedInstances(), }; } @@ -246,11 +236,9 @@ export class AdminSettings extends Component { themeList: [], }); - const auth = myAuthRequired(); - const [bannedRes, instancesRes, themeList] = await Promise.all([ - HttpService.client.getBannedPersons({ auth }), - HttpService.client.getFederatedInstances({ auth }), + HttpService.client.getBannedPersons(), + HttpService.client.getFederatedInstances(), fetchThemeList(), ]); @@ -347,9 +335,7 @@ export class AdminSettings extends Component { async handleLeaveAdminTeam(i: AdminSettings) { i.setState({ leaveAdminTeamRes: { state: "loading" } }); this.setState({ - leaveAdminTeamRes: await HttpService.client.leaveAdmin({ - auth: myAuthRequired(), - }), + leaveAdminTeamRes: await HttpService.client.leaveAdmin(), }); if (this.state.leaveAdminTeamRes.state === "success") { diff --git a/src/shared/components/home/emojis-form.tsx b/src/shared/components/home/emojis-form.tsx index 93c5d207..3121bc14 100644 --- a/src/shared/components/home/emojis-form.tsx +++ b/src/shared/components/home/emojis-form.tsx @@ -1,4 +1,4 @@ -import { myAuthRequired, setIsoData } from "@utils/app"; +import { setIsoData } from "@utils/app"; import { capitalizeFirstLetter } from "@utils/helpers"; import { Component, linkEvent } from "inferno"; import { @@ -418,7 +418,6 @@ export class EmojiForm extends Component { if (d.cv.id !== 0) { d.i.props.onDelete({ id: d.cv.id, - auth: myAuthRequired(), }); } else { const custom_emojis = [...d.i.state.customEmojis]; @@ -439,7 +438,6 @@ export class EmojiForm extends Component { image_url: d.cv.image_url, alt_text: d.cv.alt_text, keywords: uniqueKeywords, - auth: myAuthRequired(), }); } else { d.i.props.onCreate({ @@ -448,7 +446,6 @@ export class EmojiForm extends Component { image_url: d.cv.image_url, alt_text: d.cv.alt_text, keywords: uniqueKeywords, - auth: myAuthRequired(), }); } } diff --git a/src/shared/components/home/home.tsx b/src/shared/components/home/home.tsx index 1055700a..97dd89ca 100644 --- a/src/shared/components/home/home.tsx +++ b/src/shared/components/home/home.tsx @@ -129,7 +129,6 @@ type HomeData = RouteDataResponse<{ function getRss(listingType: ListingType) { const { sort } = getHomeQueryParams(); - const auth = myAuth(); let rss: string | undefined = undefined; @@ -143,6 +142,7 @@ function getRss(listingType: ListingType) { break; } case "Subscribed": { + const auth = myAuth(); rss = auth ? `/feeds/front/${auth}.xml?sort=${sort}` : undefined; break; } @@ -310,7 +310,6 @@ export class Home extends Component { static async fetchInitialData({ client, - auth, query: { dataType: urlDataType, listingType, page: urlPage, sort: urlSort }, site, }: InitialFetchRequest>): Promise { @@ -334,7 +333,6 @@ export class Home extends Component { limit: fetchLimit, sort, saved_only: false, - auth, }; postsRes = await client.getPosts(getPostsForm); @@ -345,7 +343,6 @@ export class Home extends Component { sort: postToCommentSortType(sort), type_, saved_only: false, - auth, }; commentsRes = await client.getComments(getCommentsForm); @@ -355,7 +352,6 @@ export class Home extends Component { type_: "Local", sort: "Hot", limit: trendingFetchLimit, - auth, }; return { @@ -800,13 +796,11 @@ export class Home extends Component { type_: "Local", sort: "Hot", limit: trendingFetchLimit, - auth: myAuth(), }), }); } async fetchData() { - const auth = myAuth(); const { dataType, page, listingType, sort } = getHomeQueryParams(); if (dataType === DataType.Post) { @@ -828,7 +822,6 @@ export class Home extends Component { sort, saved_only: false, type_: listingType, - auth, }), }); @@ -843,7 +836,6 @@ export class Home extends Component { sort: postToCommentSortType(sort), saved_only: false, type_: listingType, - auth, }), }); } diff --git a/src/shared/components/home/instances.tsx b/src/shared/components/home/instances.tsx index afdcddb4..4edc6056 100644 --- a/src/shared/components/home/instances.tsx +++ b/src/shared/components/home/instances.tsx @@ -58,7 +58,7 @@ export class Instances extends Component { }); this.setState({ - instancesRes: await HttpService.client.getFederatedInstances({}), + instancesRes: await HttpService.client.getFederatedInstances(), }); } @@ -66,7 +66,7 @@ export class Instances extends Component { client, }: InitialFetchRequest): Promise { return { - federatedInstancesResponse: await client.getFederatedInstances({}), + federatedInstancesResponse: await client.getFederatedInstances(), }; } diff --git a/src/shared/components/home/login.tsx b/src/shared/components/home/login.tsx index b715219a..3fa10a4e 100644 --- a/src/shared/components/home/login.tsx +++ b/src/shared/components/home/login.tsx @@ -1,4 +1,4 @@ -import { myAuth, setIsoData } from "@utils/app"; +import { setIsoData } from "@utils/app"; import { isBrowser } from "@utils/browser"; import { getQueryParams } from "@utils/helpers"; import { Component, linkEvent } from "inferno"; @@ -62,9 +62,7 @@ async function handleLoginSubmit(i: Login, event: any) { UserService.Instance.login({ res: loginRes.data, }); - const site = await HttpService.client.getSite({ - auth: myAuth(), - }); + const site = await HttpService.client.getSite(); if (site.state === "success") { UserService.Instance.myUserInfo = site.data.my_user; diff --git a/src/shared/components/home/rate-limit-form.tsx b/src/shared/components/home/rate-limit-form.tsx index 2ae6ba23..21b3364b 100644 --- a/src/shared/components/home/rate-limit-form.tsx +++ b/src/shared/components/home/rate-limit-form.tsx @@ -1,4 +1,3 @@ -import { myAuthRequired } from "@utils/app"; import { capitalizeFirstLetter } from "@utils/helpers"; import classNames from "classnames"; import { Component, FormEventHandler, linkEvent } from "inferno"; @@ -114,15 +113,12 @@ function handlePerSecondChange( function submitRateLimitForm(i: RateLimitsForm, event: any) { event.preventDefault(); - const auth = myAuthRequired(); const form: EditSite = Object.entries(i.state.form).reduce( (acc, [key, val]) => { acc[`rate_limit_${key}`] = val; return acc; }, - { - auth, - }, + {}, ); i.props.onSaveSite(form); diff --git a/src/shared/components/home/signup.tsx b/src/shared/components/home/signup.tsx index 58324bef..c7256aa9 100644 --- a/src/shared/components/home/signup.tsx +++ b/src/shared/components/home/signup.tsx @@ -1,4 +1,4 @@ -import { myAuth, setIsoData } from "@utils/app"; +import { setIsoData } from "@utils/app"; import { isBrowser } from "@utils/browser"; import { validEmail } from "@utils/helpers"; import { Component, linkEvent } from "inferno"; @@ -67,7 +67,7 @@ export class Signup extends Component { async fetchCaptcha() { this.setState({ captchaRes: { state: "loading" } }); this.setState({ - captchaRes: await HttpService.client.getCaptcha({}), + captchaRes: await HttpService.client.getCaptcha(), }); this.setState(s => { @@ -397,7 +397,7 @@ export class Signup extends Component { res: data, }); - const site = await HttpService.client.getSite({ auth: myAuth() }); + const site = await HttpService.client.getSite(); if (site.state === "success") { UserService.Instance.myUserInfo = site.data.my_user; diff --git a/src/shared/components/home/site-form.tsx b/src/shared/components/home/site-form.tsx index da220718..876d9449 100644 --- a/src/shared/components/home/site-form.tsx +++ b/src/shared/components/home/site-form.tsx @@ -1,4 +1,3 @@ -import { myAuthRequired } from "@utils/app"; import { capitalizeFirstLetter, validInstanceTLD } from "@utils/helpers"; import { Component, @@ -85,7 +84,6 @@ export class SiteForm extends Component { captcha_difficulty: ls.captcha_difficulty, allowed_instances: this.props.allowedInstances?.map(i => i.domain), blocked_instances: this.props.blockedInstances?.map(i => i.domain), - auth: "TODO", }; } @@ -733,8 +731,6 @@ export class SiteForm extends Component { handleSaveSiteSubmit(i: SiteForm, event: any) { event.preventDefault(); - const auth = myAuthRequired(); - i.setState(s => ((s.siteForm.auth = auth), s)); i.setState({ submitted: true }); const stateSiteForm = i.state.siteForm; @@ -788,7 +784,6 @@ export class SiteForm extends Component { allowed_instances: stateSiteForm.allowed_instances, blocked_instances: stateSiteForm.blocked_instances, discussion_languages: stateSiteForm.discussion_languages, - auth, }; } diff --git a/src/shared/components/home/tagline-form.tsx b/src/shared/components/home/tagline-form.tsx index 2d9d93bb..e4625028 100644 --- a/src/shared/components/home/tagline-form.tsx +++ b/src/shared/components/home/tagline-form.tsx @@ -1,4 +1,3 @@ -import { myAuthRequired } from "@utils/app"; import { capitalizeFirstLetter } from "@utils/helpers"; import { Component, InfernoMouseEvent, linkEvent } from "inferno"; import { EditSite, Tagline } from "lemmy-js-client"; @@ -143,7 +142,6 @@ export class TaglineForm extends Component { async handleSaveClick(i: TaglineForm) { i.props.onSaveSite({ taglines: i.state.taglines, - auth: myAuthRequired(), }); } diff --git a/src/shared/components/modlog.tsx b/src/shared/components/modlog.tsx index 88b642c6..87e378ef 100644 --- a/src/shared/components/modlog.tsx +++ b/src/shared/components/modlog.tsx @@ -1,7 +1,6 @@ import { fetchUsers, getUpdatedSearchId, - myAuth, personToChoice, setIsoData, } from "@utils/app"; @@ -951,7 +950,6 @@ export class Modlog extends Component< } async refetch() { - const auth = myAuth(); const { actionType, page, modId, userId } = getModlogQueryParams(); const { communityId: urlCommunityId } = this.props.match.params; const communityId = getIdFromString(urlCommunityId); @@ -968,7 +966,6 @@ export class Modlog extends Component< .hide_modlog_mod_names ? modId ?? undefined : undefined, - auth, }), }); @@ -977,7 +974,6 @@ export class Modlog extends Component< this.setState({ communityRes: await HttpService.client.getCommunity({ id: communityId, - auth, }), }); } @@ -987,7 +983,6 @@ export class Modlog extends Component< client, path, query: { modId: urlModId, page, userId: urlUserId, actionType }, - auth, site, }: InitialFetchRequest>): Promise { const pathSplit = path.split("/"); @@ -1004,7 +999,6 @@ export class Modlog extends Component< type_: getActionFromString(actionType), mod_person_id: modId, other_person_id: userId, - auth, }; let communityResponse: RequestState = { @@ -1014,7 +1008,6 @@ export class Modlog extends Component< if (communityId) { const communityForm: GetCommunity = { id: communityId, - auth, }; communityResponse = await client.getCommunity(communityForm); @@ -1027,7 +1020,6 @@ export class Modlog extends Component< if (modId) { const getPersonForm: GetPersonDetails = { person_id: modId, - auth, }; modUserResponse = await client.getPersonDetails(getPersonForm); @@ -1040,7 +1032,6 @@ export class Modlog extends Component< if (userId) { const getPersonForm: GetPersonDetails = { person_id: userId, - auth, }; userResponse = await client.getPersonDetails(getPersonForm); diff --git a/src/shared/components/person/inbox.tsx b/src/shared/components/person/inbox.tsx index af4dfee7..992f308a 100644 --- a/src/shared/components/person/inbox.tsx +++ b/src/shared/components/person/inbox.tsx @@ -7,7 +7,6 @@ import { enableDownvotes, getCommentParentId, myAuth, - myAuthRequired, setIsoData, updatePersonBlock, } from "@utils/app"; @@ -63,7 +62,11 @@ import { import { fetchLimit, relTags } from "../../config"; import { CommentViewType, InitialFetchRequest } from "../../interfaces"; import { FirstLoadService, I18NextService, UserService } from "../../services"; -import { HttpService, RequestState } from "../../services/HttpService"; +import { + EmptyRequestState, + HttpService, + RequestState, +} from "../../services/HttpService"; import { toast } from "../../toast"; import { CommentNodes } from "../comment/comment-nodes"; import { CommentSortSelect } from "../common/comment-sort-select"; @@ -719,38 +722,40 @@ export class Inbox extends Component { static async fetchInitialData({ client, - auth, }: InitialFetchRequest): Promise { const sort: CommentSortType = "New"; - - return { - mentionsRes: auth - ? await client.getPersonMentions({ - sort, - unread_only: true, - page: 1, - limit: fetchLimit, - auth, - }) - : { state: "empty" }, - messagesRes: auth - ? await client.getPrivateMessages({ - unread_only: true, - page: 1, - limit: fetchLimit, - auth, - }) - : { state: "empty" }, - repliesRes: auth - ? await client.getReplies({ - sort, - unread_only: true, - page: 1, - limit: fetchLimit, - auth, - }) - : { state: "empty" }, + const empty: EmptyRequestState = { state: "empty" }; + let inboxData: InboxData = { + mentionsRes: empty, + messagesRes: empty, + repliesRes: empty, }; + + if (myAuth()) { + const [mentionsRes, messagesRes, repliesRes] = await Promise.all([ + client.getPersonMentions({ + sort, + unread_only: true, + page: 1, + limit: fetchLimit, + }), + client.getPrivateMessages({ + unread_only: true, + page: 1, + limit: fetchLimit, + }), + client.getReplies({ + sort, + unread_only: true, + page: 1, + limit: fetchLimit, + }), + ]); + + inboxData = { mentionsRes, messagesRes, repliesRes }; + } + + return inboxData; } async refetch() { @@ -758,7 +763,6 @@ export class Inbox extends Component { const unread_only = this.state.unreadOrAll === UnreadOrAll.Unread; const page = this.state.page; const limit = fetchLimit; - const auth = myAuthRequired(); this.setState({ repliesRes: { state: "loading" } }); this.setState({ @@ -767,7 +771,6 @@ export class Inbox extends Component { unread_only, page, limit, - auth, }), }); @@ -778,7 +781,6 @@ export class Inbox extends Component { unread_only, page, limit, - auth, }), }); @@ -788,7 +790,6 @@ export class Inbox extends Component { unread_only, page, limit, - auth, }), }); } @@ -802,9 +803,7 @@ export class Inbox extends Component { i.setState({ markAllAsReadRes: { state: "loading" } }); i.setState({ - markAllAsReadRes: await HttpService.client.markAllAsRead({ - auth: myAuthRequired(), - }), + markAllAsReadRes: await HttpService.client.markAllAsRead(), }); if (i.state.markAllAsReadRes.state === "success") { diff --git a/src/shared/components/person/password-change.tsx b/src/shared/components/person/password-change.tsx index 16f23d4b..1acfee49 100644 --- a/src/shared/components/person/password-change.tsx +++ b/src/shared/components/person/password-change.tsx @@ -1,4 +1,4 @@ -import { myAuth, setIsoData } from "@utils/app"; +import { setIsoData } from "@utils/app"; import { capitalizeFirstLetter } from "@utils/helpers"; import { Component, linkEvent } from "inferno"; import { GetSiteResponse, LoginResponse } from "lemmy-js-client"; @@ -126,7 +126,7 @@ export class PasswordChange extends Component { res: data, }); - const site = await HttpService.client.getSite({ auth: myAuth() }); + const site = await HttpService.client.getSite(); if (site.state === "success") { UserService.Instance.myUserInfo = site.data.my_user; } diff --git a/src/shared/components/person/profile.tsx b/src/shared/components/person/profile.tsx index c8119b8c..6b95a44a 100644 --- a/src/shared/components/person/profile.tsx +++ b/src/shared/components/person/profile.tsx @@ -5,8 +5,6 @@ import { enableDownvotes, enableNsfw, getCommentParentId, - myAuth, - myAuthRequired, setIsoData, updatePersonBlock, } from "@utils/app"; @@ -243,7 +241,6 @@ export class Profile extends Component< saved_only: view === PersonDetailsView.Saved, page, limit: fetchLimit, - auth: myAuth(), }), }); restoreScrollPosition(this.context); @@ -278,7 +275,6 @@ export class Profile extends Component< client, path, query: { page, sort, view: urlView }, - auth, }: InitialFetchRequest>): Promise { const pathSplit = path.split("/"); @@ -291,7 +287,6 @@ export class Profile extends Component< saved_only: view === PersonDetailsView.Saved, page: getPageFromString(page), limit: fetchLimit, - auth, }; return { @@ -782,7 +777,6 @@ export class Profile extends Component< remove_data: removeData, reason: banReason, expires: futureDaysToUnixTime(banExpireDays), - auth: myAuthRequired(), }); // TODO this.updateBan(res); @@ -794,7 +788,6 @@ export class Profile extends Component< const res = await HttpService.client.blockPerson({ person_id: recipientId, block, - auth: myAuthRequired(), }); if (res.state === "success") { updatePersonBlock(res.data); diff --git a/src/shared/components/person/registration-applications.tsx b/src/shared/components/person/registration-applications.tsx index fb603bf5..ac752f32 100644 --- a/src/shared/components/person/registration-applications.tsx +++ b/src/shared/components/person/registration-applications.tsx @@ -1,8 +1,4 @@ -import { - editRegistrationApplication, - myAuthRequired, - setIsoData, -} from "@utils/app"; +import { editRegistrationApplication, myAuth, setIsoData } from "@utils/app"; import { randomStr } from "@utils/helpers"; import { RouteDataResponse } from "@utils/types"; import classNames from "classnames"; @@ -205,16 +201,14 @@ export class RegistrationApplications extends Component< } static async fetchInitialData({ - auth, client, }: InitialFetchRequest): Promise { return { - listRegistrationApplicationsResponse: auth + listRegistrationApplicationsResponse: myAuth() ? await client.listRegistrationApplications({ unread_only: true, page: 1, limit: fetchLimit, - auth: auth as string, }) : { state: "empty" }, }; @@ -230,7 +224,6 @@ export class RegistrationApplications extends Component< unread_only: unread_only, page: this.state.page, limit: fetchLimit, - auth: myAuthRequired(), }), }); } diff --git a/src/shared/components/person/reports.tsx b/src/shared/components/person/reports.tsx index 35f8e759..9de8463e 100644 --- a/src/shared/components/person/reports.tsx +++ b/src/shared/components/person/reports.tsx @@ -2,7 +2,6 @@ import { editCommentReport, editPostReport, editPrivateMessageReport, - myAuthRequired, setIsoData, } from "@utils/app"; import { randomStr } from "@utils/helpers"; @@ -531,7 +530,6 @@ export class Reports extends Component { } static async fetchInitialData({ - auth, client, }: InitialFetchRequest): Promise { const unresolved_only = true; @@ -542,14 +540,12 @@ export class Reports extends Component { unresolved_only, page, limit, - auth: auth as string, }; const postReportsForm: ListPostReports = { unresolved_only, page, limit, - auth: auth as string, }; const data: ReportsData = { @@ -563,7 +559,6 @@ export class Reports extends Component { unresolved_only, page, limit, - auth: auth as string, }; data.messageReportsRes = await client.listPrivateMessageReports( @@ -578,7 +573,6 @@ export class Reports extends Component { const unresolved_only = this.state.unreadOrAll === UnreadOrAll.Unread; const page = this.state.page; const limit = fetchLimit; - const auth = myAuthRequired(); this.setState({ commentReportsRes: { state: "loading" }, @@ -593,7 +587,6 @@ export class Reports extends Component { unresolved_only, page, limit, - auth, }; this.setState({ diff --git a/src/shared/components/person/settings.tsx b/src/shared/components/person/settings.tsx index a606a19d..607429f0 100644 --- a/src/shared/components/person/settings.tsx +++ b/src/shared/components/person/settings.tsx @@ -4,7 +4,6 @@ import { fetchThemeList, fetchUsers, myAuth, - myAuthRequired, personToChoice, setIsoData, setTheme, @@ -993,7 +992,6 @@ export class Settings extends Component { const res = await HttpService.client.blockPerson({ person_id: Number(value), block: true, - auth: myAuthRequired(), }); this.personBlock(res); } @@ -1009,7 +1007,6 @@ export class Settings extends Component { const res = await HttpService.client.blockPerson({ person_id: recipientId, block: false, - auth: myAuthRequired(), }); ctx.personBlock(res); } @@ -1019,19 +1016,16 @@ export class Settings extends Component { const res = await HttpService.client.blockCommunity({ community_id: Number(value), block: true, - auth: myAuthRequired(), }); this.communityBlock(res); } } async handleUnblockCommunity(i: { ctx: Settings; communityId: number }) { - const auth = myAuth(); - if (auth) { + if (myAuth()) { const res = await HttpService.client.blockCommunity({ community_id: i.communityId, block: false, - auth: myAuthRequired(), }); i.ctx.communityBlock(res); } @@ -1232,7 +1226,6 @@ export class Settings extends Component { const saveRes = await HttpService.client.saveUserSettings({ ...i.state.saveUserSettingsForm, - auth: myAuthRequired(), }); if (saveRes.state === "success") { @@ -1258,7 +1251,6 @@ export class Settings extends Component { new_password, new_password_verify, old_password, - auth: myAuthRequired(), }); if (changePasswordRes.state === "success") { UserService.Instance.login({ @@ -1288,8 +1280,7 @@ export class Settings extends Component { i.setState({ deleteAccountRes: { state: "loading" } }); const deleteAccountRes = await HttpService.client.deleteAccount({ password, - auth: myAuthRequired(), - // TODO: promt user weather he wants the content to be deleted, + // TODO: promt user weather he wants the content to be deleted delete_content: false, }); if (deleteAccountRes.state === "success") { diff --git a/src/shared/components/post/create-post.tsx b/src/shared/components/post/create-post.tsx index 3c312c32..b447cf14 100644 --- a/src/shared/components/post/create-post.tsx +++ b/src/shared/components/post/create-post.tsx @@ -1,4 +1,4 @@ -import { enableDownvotes, enableNsfw, myAuth, setIsoData } from "@utils/app"; +import { enableDownvotes, enableNsfw, setIsoData } from "@utils/app"; import { getIdFromString, getQueryParams } from "@utils/helpers"; import type { QueryParams } from "@utils/types"; import { Choice, RouteDataResponse } from "@utils/types"; @@ -96,12 +96,10 @@ export class CreatePost extends Component< async fetchCommunity() { const { communityId } = getCreatePostQueryParams(); - const auth = myAuth(); if (communityId) { const res = await HttpService.client.getCommunity({ id: communityId, - auth, }); if (res.state === "success") { this.setState({ @@ -239,7 +237,6 @@ export class CreatePost extends Component< static async fetchInitialData({ client, query: { communityId }, - auth, }: InitialFetchRequest< QueryParams >): Promise { @@ -250,7 +247,6 @@ export class CreatePost extends Component< if (communityId) { const form: GetCommunity = { - auth, id: getIdFromString(communityId), }; diff --git a/src/shared/components/post/post-form.tsx b/src/shared/components/post/post-form.tsx index 301cf43f..406d86ea 100644 --- a/src/shared/components/post/post-form.tsx +++ b/src/shared/components/post/post-form.tsx @@ -1,9 +1,4 @@ -import { - communityToChoice, - fetchCommunities, - myAuth, - myAuthRequired, -} from "@utils/app"; +import { communityToChoice, fetchCommunities } from "@utils/app"; import { capitalizeFirstLetter, debounce, @@ -89,7 +84,6 @@ function handlePostSubmit(i: PostForm, event: any) { i.setState(s => ((s.form.url = undefined), s)); } i.setState({ loading: true, submitted: true }); - const auth = myAuthRequired(); const pForm = i.state.form; const pv = i.props.post_view; @@ -102,7 +96,6 @@ function handlePostSubmit(i: PostForm, event: any) { nsfw: pForm.nsfw, post_id: pv.post.id, language_id: pForm.language_id, - auth, }); } else if (pForm.name && pForm.community_id) { i.props.onCreate?.({ @@ -113,7 +106,6 @@ function handlePostSubmit(i: PostForm, event: any) { nsfw: pForm.nsfw, language_id: pForm.language_id, honeypot: pForm.honeypot, - auth, }); } } @@ -676,7 +668,6 @@ export class PostForm extends Component { community_id: this.state.form.community_id, page: 1, limit: trendingFetchLimit, - auth: myAuth(), }), }); } diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index 649710bc..9a8bea09 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -1,4 +1,4 @@ -import { myAuth, myAuthRequired } from "@utils/app"; +import { myAuth } from "@utils/app"; import { canShare, share } from "@utils/browser"; import { getExternalHost, getHttpBase } from "@utils/env"; import { @@ -1444,7 +1444,6 @@ export class PostListing extends Component { this.props.onPostReport({ post_id: this.postView.post.id, reason, - auth: myAuthRequired(), }); this.setState({ @@ -1457,7 +1456,6 @@ export class PostListing extends Component { i.props.onBlockPerson({ person_id: i.postView.creator.id, block: true, - auth: myAuthRequired(), }); } @@ -1466,7 +1464,6 @@ export class PostListing extends Component { i.props.onDeletePost({ post_id: i.postView.post.id, deleted: !i.postView.post.deleted, - auth: myAuthRequired(), }); } @@ -1475,7 +1472,6 @@ export class PostListing extends Component { i.props.onSavePost({ post_id: i.postView.post.id, save: !i.postView.saved, - auth: myAuthRequired(), }); } @@ -1533,7 +1529,6 @@ export class PostListing extends Component { i.props.onRemovePost({ post_id: i.postView.post.id, removed: !i.postView.post.removed, - auth: myAuthRequired(), reason: i.state.removeReason, }); } @@ -1543,7 +1538,6 @@ export class PostListing extends Component { i.props.onLockPost({ post_id: i.postView.post.id, locked: !i.postView.post.locked, - auth: myAuthRequired(), }); } @@ -1553,7 +1547,6 @@ export class PostListing extends Component { post_id: i.postView.post.id, featured: !i.postView.post.featured_local, feature_type: "Local", - auth: myAuthRequired(), }); } @@ -1563,7 +1556,6 @@ export class PostListing extends Component { post_id: i.postView.post.id, featured: !i.postView.post.featured_community, feature_type: "Community", - auth: myAuthRequired(), }); } @@ -1610,13 +1602,11 @@ export class PostListing extends Component { i.props.onPurgePerson({ person_id: i.postView.creator.id, reason: i.state.purgeReason, - auth: myAuthRequired(), }); } else if (i.state.purgeType === PurgeType.Post) { i.props.onPurgePost({ post_id: i.postView.post.id, reason: i.state.purgeReason, - auth: myAuthRequired(), }); } } @@ -1662,7 +1652,6 @@ export class PostListing extends Component { remove_data, reason, expires, - auth: myAuthRequired(), }); } else { i.props.onBanPerson({ @@ -1671,7 +1660,6 @@ export class PostListing extends Component { remove_data, reason, expires, - auth: myAuthRequired(), }); } } @@ -1682,7 +1670,6 @@ export class PostListing extends Component { community_id: i.postView.community.id, person_id: i.postView.creator.id, added: !i.creatorIsMod_, - auth: myAuthRequired(), }); } @@ -1691,7 +1678,6 @@ export class PostListing extends Component { i.props.onAddAdmin({ person_id: i.postView.creator.id, added: !i.creatorIsAdmin_, - auth: myAuthRequired(), }); } @@ -1708,7 +1694,6 @@ export class PostListing extends Component { i.props.onTransferCommunity({ community_id: i.postView.community.id, person_id: i.postView.creator.id, - auth: myAuthRequired(), }); } @@ -1725,12 +1710,10 @@ export class PostListing extends Component { i.setState({ imageExpanded: !i.state.imageExpanded }); setupTippy(); - const auth = myAuth(); - if (auth && !i.props.post_view.read) { + if (myAuth() && !i.props.post_view.read) { i.props.onMarkPostAsRead({ post_id: i.props.post_view.post.id, read: true, - auth: auth, }); } } diff --git a/src/shared/components/post/post-report.tsx b/src/shared/components/post/post-report.tsx index fd6d99ba..ea3b68cf 100644 --- a/src/shared/components/post/post-report.tsx +++ b/src/shared/components/post/post-report.tsx @@ -1,4 +1,3 @@ -import { myAuthRequired } from "@utils/app"; import { Component, InfernoNode, linkEvent } from "inferno"; import { T } from "inferno-i18next-dess"; import { PostReportView, PostView, ResolvePostReport } from "lemmy-js-client"; @@ -137,7 +136,6 @@ export class PostReport extends Component { i.props.onResolveReport({ report_id: i.props.report.post_report.id, resolved: !i.props.report.post_report.resolved, - auth: myAuthRequired(), }); } } diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx index 77fe7804..25514208 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -9,7 +9,6 @@ import { getCommentParentId, getDepthFromComment, getIdFromProps, - myAuth, setIsoData, updateCommunityBlock, updatePersonBlock, @@ -201,23 +200,24 @@ export class Post extends Component { commentsRes: { state: "loading" }, }); - const auth = myAuth(); - - this.setState({ - postRes: await HttpService.client.getPost({ + const [postRes, commentsRes] = await Promise.all([ + await HttpService.client.getPost({ id: this.state.postId, comment_id: this.state.commentId, - auth, }), - commentsRes: await HttpService.client.getComments({ + HttpService.client.getComments({ post_id: this.state.postId, parent_id: this.state.commentId, max_depth: commentTreeMaxDepth, sort: this.state.commentSort, type_: "All", saved_only: false, - auth, }), + ]); + + this.setState({ + postRes, + commentsRes, }); setupTippy(); @@ -232,23 +232,19 @@ export class Post extends Component { static async fetchInitialData({ client, path, - auth, }: InitialFetchRequest): Promise { const pathSplit = path.split("/"); const pathType = pathSplit.at(1); const id = pathSplit.at(2) ? Number(pathSplit.at(2)) : undefined; - const postForm: GetPost = { - auth, - }; + const postForm: GetPost = {}; const commentsForm: GetComments = { max_depth: commentTreeMaxDepth, sort: "Hot", type_: "All", saved_only: false, - auth, }; // Set the correct id based on the path type diff --git a/src/shared/components/private_message/create-private-message.tsx b/src/shared/components/private_message/create-private-message.tsx index 805b3ec9..cbe25d79 100644 --- a/src/shared/components/private_message/create-private-message.tsx +++ b/src/shared/components/private_message/create-private-message.tsx @@ -1,4 +1,4 @@ -import { getRecipientIdFromProps, myAuth, setIsoData } from "@utils/app"; +import { getRecipientIdFromProps, setIsoData } from "@utils/app"; import { RouteDataResponse } from "@utils/types"; import { Component } from "inferno"; import { @@ -62,7 +62,6 @@ export class CreatePrivateMessage extends Component< static async fetchInitialData({ client, path, - auth, }: InitialFetchRequest): Promise { const person_id = Number(path.split("/").pop()); @@ -70,7 +69,6 @@ export class CreatePrivateMessage extends Component< person_id, sort: "New", saved_only: false, - auth, }; return { @@ -88,7 +86,6 @@ export class CreatePrivateMessage extends Component< person_id: this.state.recipientId, sort: "New", saved_only: false, - auth: myAuth(), }), }); } diff --git a/src/shared/components/private_message/private-message-form.tsx b/src/shared/components/private_message/private-message-form.tsx index ef534308..1139ade7 100644 --- a/src/shared/components/private_message/private-message-form.tsx +++ b/src/shared/components/private_message/private-message-form.tsx @@ -1,4 +1,3 @@ -import { myAuthRequired } from "@utils/app"; import { capitalizeFirstLetter } from "@utils/helpers"; import { Component, InfernoNode } from "inferno"; import { T } from "inferno-i18next-dess"; @@ -128,19 +127,16 @@ export class PrivateMessageForm extends Component< event.preventDefault(); i.setState({ loading: true, submitted: true }); const pm = i.props.privateMessageView; - const auth = myAuthRequired(); const content = i.state.content ?? ""; if (pm) { i.props.onEdit?.({ private_message_id: pm.private_message.id, content, - auth, }); } else { i.props.onCreate?.({ content, recipient_id: i.props.recipient.id, - auth, }); } } diff --git a/src/shared/components/private_message/private-message-report.tsx b/src/shared/components/private_message/private-message-report.tsx index 1aa3d7c3..fee8c9c7 100644 --- a/src/shared/components/private_message/private-message-report.tsx +++ b/src/shared/components/private_message/private-message-report.tsx @@ -1,4 +1,3 @@ -import { myAuthRequired } from "@utils/app"; import { Component, InfernoNode, linkEvent } from "inferno"; import { T } from "inferno-i18next-dess"; import { @@ -105,7 +104,6 @@ export class PrivateMessageReport extends Component { i.props.onResolveReport({ report_id: pmr.id, resolved: !pmr.resolved, - auth: myAuthRequired(), }); } } diff --git a/src/shared/components/private_message/private-message.tsx b/src/shared/components/private_message/private-message.tsx index cc09418c..035983f8 100644 --- a/src/shared/components/private_message/private-message.tsx +++ b/src/shared/components/private_message/private-message.tsx @@ -1,4 +1,3 @@ -import { myAuthRequired } from "@utils/app"; import { Component, InfernoNode, linkEvent } from "inferno"; import { CreatePrivateMessage, @@ -304,7 +303,6 @@ export class PrivateMessage extends Component< i.props.onDelete({ private_message_id: i.props.private_message_view.private_message.id, deleted: !i.props.private_message_view.private_message.deleted, - auth: myAuthRequired(), }); } @@ -317,7 +315,6 @@ export class PrivateMessage extends Component< i.props.onMarkRead({ private_message_id: i.props.private_message_view.private_message.id, read: !i.props.private_message_view.private_message.read, - auth: myAuthRequired(), }); } @@ -337,7 +334,6 @@ export class PrivateMessage extends Component< this.props.onReport({ private_message_id: this.props.private_message_view.private_message.id, reason, - auth: myAuthRequired(), }); this.setState({ diff --git a/src/shared/components/remote-fetch.tsx b/src/shared/components/remote-fetch.tsx index 55cc7c86..8f7a3f4b 100644 --- a/src/shared/components/remote-fetch.tsx +++ b/src/shared/components/remote-fetch.tsx @@ -1,4 +1,4 @@ -import { myAuthRequired, setIsoData } from "@utils/app"; +import { setIsoData } from "@utils/app"; import { getQueryParams } from "@utils/helpers"; import { QueryParams, RouteDataResponse } from "@utils/types"; import { Component, linkEvent } from "inferno"; @@ -49,7 +49,6 @@ async function handleToggleFollow(i: RemoteFetch, follow: boolean) { }); const communityRes = await HttpService.client.followCommunity({ - auth: myAuthRequired(), community_id: resolveObjectRes.data.community.community.id, follow, }); @@ -104,7 +103,6 @@ export class RemoteFetch extends Component { this.setState({ resolveObjectRes: { state: "loading" } }); this.setState({ resolveObjectRes: await HttpService.client.resolveObject({ - auth: myAuthRequired(), q: uriToQuery(uri), }), }); @@ -204,8 +202,8 @@ export class RemoteFetch extends Component { } static async fetchInitialData({ - client, auth, + client, query: { uri }, }: InitialFetchRequest< QueryParams @@ -214,7 +212,6 @@ export class RemoteFetch extends Component { if (uri && auth) { data.resolveObjectRes = await client.resolveObject({ - auth, q: uriToQuery(uri), }); } diff --git a/src/shared/components/search.tsx b/src/shared/components/search.tsx index 48f91e4c..9041d6fc 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -349,7 +349,6 @@ export class Search extends Component { type_: defaultListingType, sort: defaultSortType, limit: fetchLimit, - auth: myAuth(), }), }); } @@ -360,7 +359,6 @@ export class Search extends Component { static async fetchInitialData({ client, - auth, query: { communityId, creatorId, q, type, sort, listingType, page }, }: InitialFetchRequest>): Promise { const community_id = getIdFromString(communityId); @@ -373,7 +371,6 @@ export class Search extends Component { if (community_id) { const getCommunityForm: GetCommunity = { id: community_id, - auth, }; communityResponse = await client.getCommunity(getCommunityForm); @@ -382,7 +379,6 @@ export class Search extends Component { type_: defaultListingType, sort: defaultSortType, limit: fetchLimit, - auth, }; listCommunitiesResponse = await client.listCommunities( @@ -397,7 +393,6 @@ export class Search extends Component { if (creator_id) { const getCreatorForm: GetPersonDetails = { person_id: creator_id, - auth, }; creatorDetailsResponse = await client.getPersonDetails(getCreatorForm); @@ -420,15 +415,13 @@ export class Search extends Component { listing_type: getListingTypeFromQuery(listingType), page: getPageFromString(page), limit: fetchLimit, - auth, }; if (query !== "") { searchResponse = await client.search(form); - if (auth) { + if (myAuth()) { const resolveObjectForm: ResolveObject = { q: query, - auth, }; resolveObjectResponse = await HttpService.silent_client.resolveObject( resolveObjectForm, @@ -950,7 +943,6 @@ export class Search extends Component { } async search() { - const auth = myAuth(); const { searchText: q } = this.state; const { communityId, creatorId, type, sort, listingType, page } = getSearchQueryParams(); @@ -967,18 +959,16 @@ export class Search extends Component { listing_type: listingType, page, limit: fetchLimit, - auth, }), }); window.scrollTo(0, 0); restoreScrollPosition(this.context); - if (auth) { + if (myAuth()) { this.setState({ resolveObjectRes: { state: "loading" } }); this.setState({ resolveObjectRes: await HttpService.silent_client.resolveObject({ q, - auth, }), }); } diff --git a/src/shared/interfaces.ts b/src/shared/interfaces.ts index 7beeec99..3968d753 100644 --- a/src/shared/interfaces.ts +++ b/src/shared/interfaces.ts @@ -25,11 +25,11 @@ declare global { } export interface InitialFetchRequest { - auth?: string; client: WrappedLemmyHttp; path: string; query: T; site: GetSiteResponse; + auth?: string; } export interface PostFormParams { diff --git a/src/shared/services/UserService.ts b/src/shared/services/UserService.ts index 70e8e9ca..a82e6ea9 100644 --- a/src/shared/services/UserService.ts +++ b/src/shared/services/UserService.ts @@ -5,6 +5,7 @@ import jwt_decode from "jwt-decode"; import { LoginResponse, MyUserInfo } from "lemmy-js-client"; import { toast } from "../toast"; import { I18NextService } from "./I18NextService"; +import { HttpService } from "."; interface Claims { sub: number; @@ -81,6 +82,7 @@ export class UserService { const { jwt } = cookie.parse(document.cookie); if (jwt) { + HttpService.client.setHeaders({ Authorization: `Bearer ${jwt}` }); this.jwtInfo = { jwt, claims: jwt_decode(jwt) }; } } diff --git a/src/shared/utils/app/fetch-search-results.ts b/src/shared/utils/app/fetch-search-results.ts index 51835466..006a7084 100644 --- a/src/shared/utils/app/fetch-search-results.ts +++ b/src/shared/utils/app/fetch-search-results.ts @@ -1,4 +1,3 @@ -import { myAuth } from "@utils/app"; import { Search, SearchType } from "lemmy-js-client"; import { fetchLimit } from "../../config"; import { HttpService } from "../../services"; @@ -11,7 +10,6 @@ export default function fetchSearchResults(q: string, type_: SearchType) { listing_type: "All", page: 1, limit: fetchLimit, - auth: myAuth(), }; return HttpService.client.search(form); diff --git a/src/shared/utils/app/index.ts b/src/shared/utils/app/index.ts index 9993ac72..1a7ae1c8 100644 --- a/src/shared/utils/app/index.ts +++ b/src/shared/utils/app/index.ts @@ -35,7 +35,6 @@ import insertCommentIntoTree from "./insert-comment-into-tree"; import isAuthPath from "./is-auth-path"; import isPostBlocked from "./is-post-blocked"; import myAuth from "./my-auth"; -import myAuthRequired from "./my-auth-required"; import newVote from "./new-vote"; import nsfwCheck from "./nsfw-check"; import personSearch from "./person-search"; @@ -92,7 +91,6 @@ export { isAuthPath, isPostBlocked, myAuth, - myAuthRequired, newVote, nsfwCheck, personSearch, diff --git a/src/shared/utils/app/my-auth-required.ts b/src/shared/utils/app/my-auth-required.ts deleted file mode 100644 index e82f21cd..00000000 --- a/src/shared/utils/app/my-auth-required.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { UserService } from "../../services"; - -export default function myAuthRequired(): string { - return UserService.Instance.auth(true) ?? ""; -} diff --git a/src/shared/utils/helpers/index.ts b/src/shared/utils/helpers/index.ts index c42f9109..3420adbc 100644 --- a/src/shared/utils/helpers/index.ts +++ b/src/shared/utils/helpers/index.ts @@ -17,7 +17,6 @@ import isCakeDay from "./is-cake-day"; import numToSI from "./num-to-si"; import poll from "./poll"; import randomStr from "./random-str"; -import removeAuthParam from "./remove-auth-param"; import sleep from "./sleep"; import validEmail from "./valid-email"; import validInstanceTLD from "./valid-instance-tld"; @@ -44,7 +43,6 @@ export { numToSI, poll, randomStr, - removeAuthParam, sleep, validEmail, validInstanceTLD, diff --git a/src/shared/utils/helpers/remove-auth-param.ts b/src/shared/utils/helpers/remove-auth-param.ts deleted file mode 100644 index 0702b102..00000000 --- a/src/shared/utils/helpers/remove-auth-param.ts +++ /dev/null @@ -1,6 +0,0 @@ -export default function (err: any) { - return err - .toString() - .replace(new RegExp("[?&]auth=[^&#]*(#.*)?$"), "$1") - .replace(new RegExp("([?&])auth=[^&]*&"), "$1"); -} diff --git a/yarn.lock b/yarn.lock index 7179bb2c..5df2a0da 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6035,10 +6035,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.7: - version "0.19.0-rc.7" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.19.0-rc.7.tgz#822dd85c44c2df03eafb71c6e046dbeeb6ed854d" - integrity sha512-dqnyepju5sCRu+zwwm8GeQtXJpRnz/mARo//fZBPz1EgNA70crWheamBoJ9GSm19znsZzu0853t8GxVhNT9iIw== +lemmy-js-client@^0.19.0-rc.12: + version "0.19.0-rc.12" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.19.0-rc.12.tgz#e3bd4e21b1966d583ab790ef70ece8394b012b48" + integrity sha512-1iu2fW9vlb3TrI+QR/ODP3+5pWZB0rUqL1wH09IzomDXohCqoQvfmXpwArmgF4Eq8GZgjkcfeMDC2gMrfw/i7Q== dependencies: cross-fetch "^3.1.5" form-data "^4.0.0"