Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fetch instead of axios #4392

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions frontend/orval.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ module.exports = {
target: "./",
schemas: "./model",
client: "react-query",
baseUrl: "${process.env.NEXT_PUBLIC_API_BASE_URI}",
httpClient: "fetch",
urlEncodeParameters: true,
mock: true,
prettier: true,
clean: true,
Expand Down
1 change: 0 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@stripe/stripe-js": "^5.2.0",
"@tanstack/react-query": "^5.62.11",
"@tanstack/react-table": "^8.20.6",
"axios": "^1.7.9",
"boring-avatars": "^1.11.2",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
Expand Down
8 changes: 0 additions & 8 deletions frontend/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { ReactQueryDevtools } from "@tanstack/react-query-devtools"
import cardImage from "../public/img/card.webp"
import { Fragment, ReactElement, ReactNode, useState } from "react"
import { setDefaultOptions } from "date-fns"
import axios from "axios"
import { NextPage } from "next"
import { Toaster } from "@/components/ui/sonner"

Expand All @@ -49,13 +48,6 @@ const App = ({ Component, pageProps }: AppPropsWithLayout) => {

const [queryClient] = useState(() => new QueryClient({}))

axios.interceptors.request.use((config) => {
return {
...config,
baseURL: process.env.NEXT_PUBLIC_API_BASE_URI,
}
})

const router = useRouter()
const instance = createInstance({
urlBase: process.env.NEXT_PUBLIC_SITE_BASE_URI || "",
Expand Down
4 changes: 2 additions & 2 deletions frontend/pages/admin/app-picks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default function AppPicks() {
position: app.position,
},
{
withCredentials: true,
credentials: "include",
},
)

Expand Down Expand Up @@ -199,7 +199,7 @@ export default function AppPicks() {
recommendation_date: formatISO(date, { representation: "date" }),
},
{
withCredentials: true,
credentials: "include",
},
)

Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/admin/quality-moderation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function QualityModerationDashboard() {
filter: filteredBy,
},
{
withCredentials: true,
credentials: "include",
signal,
},
),
Expand Down
8 changes: 4 additions & 4 deletions frontend/pages/admin/roles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ UserModeration.getLayout = function getLayout(page: ReactElement) {

export default function UserModeration() {
const rolesQuery = useRolesUsersRolesGet({
axios: {
withCredentials: true,
fetch: {
credentials: "include",
},
})

Expand Down Expand Up @@ -64,8 +64,8 @@ export default function UserModeration() {

const UserList = ({ role }: { role: string }) => {
const query = useRoleUsersUsersRolesRoleNameGet(role as RoleName, {
axios: {
withCredentials: true,
fetch: {
credentials: "include",
},
})

Expand Down
12 changes: 6 additions & 6 deletions frontend/pages/admin/users/[user].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ const ProviderProfileLink = ({

export default function UserAdmin({ userId }) {
const query = useUserUsersUserIdGet(userId, {
axios: {
withCredentials: true,
fetch: {
credentials: "include",
},
})

const addRoleQuery = useAddUserRoleUsersUserIdRolePost({
axios: {
withCredentials: true,
fetch: {
credentials: "include",
},
mutation: {
onSuccess: () => {
Expand All @@ -83,8 +83,8 @@ export default function UserAdmin({ userId }) {
})

const removeRoleQuery = useDeleteUserRoleUsersUserIdRoleDelete({
axios: {
withCredentials: true,
fetch: {
credentials: "include",
},
mutation: {
onSuccess: () => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/pages/admin/users/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export default function UserModeration() {
filterString: filterString,
},
{
axios: {
withCredentials: true,
fetch: {
credentials: "include",
},
},
)
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/apps/collection/tag/[tag]/[page].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
mapAppsIndexToAppstreamListItem,
} from "src/meilisearch"
import { getKeywordKeywordGet } from "src/codegen"
import { AxiosResponse } from "axios"

export default function Tag({
applications,
Expand Down Expand Up @@ -53,7 +52,7 @@ export const getStaticProps: GetStaticProps = async ({ locale, params }) => {
locale: locale,
page: params.page as unknown as number,
per_page: 30,
})) as AxiosResponse<MeilisearchResponse<AppsIndex>>
})) as { data: MeilisearchResponse<AppsIndex> }

if (applications.data.page > applications.data.totalPages) {
return {
Expand Down
6 changes: 3 additions & 3 deletions frontend/pages/apps/manage/[appId]/accept-invite/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function AcceptInvitePage({ app }) {
queryKey: ["invite-status", app.id],
queryFn: () =>
getInviteStatusInvitesAppIdGet(app.id, {
withCredentials: true,
credentials: "include",
}),
enabled: !!app.id,
})
Expand All @@ -41,7 +41,7 @@ export default function AcceptInvitePage({ app }) {
mutationKey: ["accept-invite", app.id],
mutationFn: () =>
acceptInviteInvitesAppIdAcceptPost(app.id, {
withCredentials: true,
credentials: "include",
}),
onSuccess: async () => {
await getUserData(userDispatch)
Expand All @@ -52,7 +52,7 @@ export default function AcceptInvitePage({ app }) {
mutationKey: ["decline-invite", app.id],
mutationFn: () =>
declineInviteInvitesAppIdDeclinePost(app.id, {
withCredentials: true,
credentials: "include",
}),
onSuccess: async () => {
await getUserData(userDispatch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const PublisherAgreementPage = ({ appId }: Props) => {
mutationKey: ["accept-invite", appId],
mutationFn: () =>
acceptInviteInvitesAppIdAcceptPost(appId, {
withCredentials: true,
credentials: "include",
}),
onSuccess: async () => {
await getUserData(userDispatch)
Expand Down
4 changes: 2 additions & 2 deletions frontend/pages/apps/manage/[appId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default function AppManagementPage({

const query = useGetAppVendingSetupVendingappAppIdSetupGet(app.id, {
query: { enabled: !!app.id },
axios: { withCredentials: true },
fetch: { credentials: "include" },
})

const pages = [
Expand All @@ -99,7 +99,7 @@ export default function AppManagementPage({
queryKey: ["invite-status", app.id],
queryFn: () =>
getInviteStatusInvitesAppIdGet(app.id, {
withCredentials: true,
credentials: "include",
}),
enabled: !!app.id,
})
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/apps/purchase/[appId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function AppPurchasePage({
queryKey: ["appVendingSetup", app.id],
queryFn: async () => {
const setup = await getAppVendingSetupVendingappAppIdSetupGet(app.id, {
withCredentials: true,
credentials: "include",
})

const decimalValue = setup.data.recommended_donation / 100
Expand Down
21 changes: 10 additions & 11 deletions frontend/pages/apps/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useQuery } from "@tanstack/react-query"
import { fetchSearchQuery } from "src/fetchers"
import { useMatomo } from "@mitresthen/matomo-tracker-react"
import { SearchPanel } from "src/components/search/SearchPanel"
import { AppsIndex, MeilisearchResponseLimited } from "src/meilisearch"

export default function Search({ locale }) {
const { t } = useTranslation()
Expand Down Expand Up @@ -43,17 +44,15 @@ export default function Search({ locale }) {
const search = useQuery({
queryKey: ["search", q, selectedFilters],
queryFn: async () => {
return fetchSearchQuery(q as string, locale, selectedFilters).then(
(res) => {
if (q.length > 0) {
trackSiteSearch({
keyword: q,
count: res.data.estimatedTotalHits,
})
}
return res
},
)
const fetch = await fetchSearchQuery(q as string, locale, selectedFilters)
const json = (await fetch.json()) as MeilisearchResponseLimited<AppsIndex>
if (q.length > 0) {
trackSiteSearch({
keyword: q,
count: json.estimatedTotalHits,
})
}
return json
},
})

Expand Down
8 changes: 4 additions & 4 deletions frontend/pages/payment/[transaction_id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export default function TransactionPage({ stripePublicKey }) {
const query = useGetTransactionByIdWalletTransactionsTxnGet(
router.query.transaction_id as string,
{
axios: {
withCredentials: true,
fetch: {
credentials: "include",
},
query: {
enabled: !!router.query.transaction_id,
Expand All @@ -38,8 +38,8 @@ export default function TransactionPage({ stripePublicKey }) {
const queryStripe = useGetTxnStripedataWalletTransactionsTxnStripeGet(
router.query.transaction_id as string,
{
axios: {
withCredentials: true,
fetch: {
credentials: "include",
},
query: {
enabled: !!router.query.transaction_id,
Expand Down
4 changes: 2 additions & 2 deletions frontend/pages/payment/details/[transaction_id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export default function TransactionPage() {
const query = useGetTransactionByIdWalletTransactionsTxnGet(
router.query.transaction_id as string,
{
axios: {
withCredentials: true,
fetch: {
credentials: "include",
},
query: {
enabled: !!router.query.transaction_id,
Expand Down
4 changes: 2 additions & 2 deletions frontend/pages/purchase/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ export default function Purchase() {
}

checkPurchasesPurchasesCheckPurchasesPost(appIDs, {
withCredentials: true,
credentials: "include",
})
.then(() => {
getUpdateTokenPurchasesGenerateUpdateTokenPost({
withCredentials: true,
credentials: "include",
})
.then((result) =>
fetch(
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/statistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ const FailedByGuideline = () => {
queryKey: ["failed-by-guideline"],
queryFn: () =>
getQualityModerationStatsQualityModerationFailedByGuidelineGet({
withCredentials: true,
credentials: "include",
}),
enabled: !!user.info?.permissions.some(
(a) => a === Permission["quality-moderation"],
Expand Down
19 changes: 8 additions & 11 deletions frontend/src/asyncs/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios, { AxiosResponse } from "axios"
import { APP_DETAILS } from "../env"
import { Appstream } from "../types/Appstream"

Expand All @@ -13,16 +12,14 @@ export async function getAppsInfo(
const responses = await Promise.allSettled(
appIds.map(async (id) => ({
id,
response: await axios
.get<Appstream>(`${APP_DETAILS(id, locale)}`)
.catch(() => {
return {
data: {
id: id,
name: id,
} as Appstream,
} as AxiosResponse<Appstream>
}),
response: await fetch(`${APP_DETAILS(id, locale)}`).catch(() => {
return {
data: {
id: id,
name: id,
} as Appstream,
}
}),
})),
)

Expand Down
10 changes: 6 additions & 4 deletions frontend/src/asyncs/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { Dispatch } from "react"
import { LOGIN_PROVIDERS_URL } from "../env"
import { APIResponseError } from "../types/API"
import { UserStateAction } from "../types/Login"
import { AxiosResponse } from "axios"
import { UserInfo } from "src/codegen/model/userInfo"
import { getUserinfoAuthUserinfoGet } from "src/codegen"
import {
getUserinfoAuthUserinfoGet,
getUserinfoAuthUserinfoGetResponse,
} from "src/codegen"

/**
* Performs the callback POST request to check 3rd party authentication
Expand Down Expand Up @@ -63,10 +65,10 @@ export async function getUserData(
dispatch({ type: "loading" })

// On network error just assume user state is unchanged
let res: AxiosResponse<UserInfo, any>
let res: getUserinfoAuthUserinfoGetResponse
try {
// Gets data for user with current session cookie
res = await getUserinfoAuthUserinfoGet({ withCredentials: true })
res = await getUserinfoAuthUserinfoGet({ credentials: "include" })

// Assuming a bad status indicates unchanged user state
// A no content status response indicates the user is not logged in
Expand Down
Loading
Loading