diff --git a/backend/src/app/controllers/job/put.ts b/backend/src/app/controllers/job/put.ts index 81b8812..7bfa94d 100644 --- a/backend/src/app/controllers/job/put.ts +++ b/backend/src/app/controllers/job/put.ts @@ -47,14 +47,15 @@ export default async (req: Request, res: Response) => { body: new URLSearchParams({ code: req.body.clientOauthCode, client_id: process.env.MODRINTH_OAUTH_CLIENT_ID, - redirect_uri: "https://ctm.oitsjustjose.com/", + redirect_uri: req.body.redirectUri, grant_type: "authorization_code", }), } ); if (!response.ok) { - return res.status(400).send(response); + const body = await response.json(); + return res.status(400).send(body); } const body = (await response.json()) as OAuthTokenResponse; diff --git a/frontend/src/pages/Home.jsx b/frontend/src/pages/Home.jsx index 2417fdd..f2d4c82 100644 --- a/frontend/src/pages/Home.jsx +++ b/frontend/src/pages/Home.jsx @@ -22,7 +22,8 @@ export default () => { /* Begins the Modrinth OAuth flow, creating a URL with a callback that has the data we need in the query params and will return back with the client's - oauth code that will be needed back on the backend + oauth code that will be needed back on the backend. When the OAuth call + succeeds, the callback will trigger the useEffect below to handle it. */ const startOauthFlow = (evt) => { evt && evt.preventDefault(); @@ -33,14 +34,16 @@ export default () => { useEffect(() => { // Handle the Modrinth OAuth callback const internalCreateJob = async (formDataIn) => { + if (!formDataIn.code.length) return; if (!formDataIn.curseforgeSlug.length) return; if (!formDataIn.modrinthId.length) return; - if (!formDataIn.code.length) return; + if (!formDataIn.redirectUri.length) return; const body = { + clientOauthCode: formDataIn.code, curseforgeSlug: formDataIn.curseforgeSlug, modrinthId: formDataIn.modrinthId, - clientOauthCode: formDataIn.code, + redirectUri: formDataIn.redirectUri, }; const resp = await fetch('/api/v1/jobs', { diff --git a/frontend/src/shared/index.js b/frontend/src/shared/index.js index 3d679d8..ab814b7 100644 --- a/frontend/src/shared/index.js +++ b/frontend/src/shared/index.js @@ -7,7 +7,6 @@ const MODRINTH_CLIENT_ID = '50zijYLk'; * @returns {string} The callback URI */ export const CreateModrinthUri = (curseforgeSlug, modrinthId) => { - console.log(process.env); const uri = new URL(`${window.location.origin}${window.location.pathname}`); uri.searchParams.set('curseforgeSlug', curseforgeSlug); uri.searchParams.set('modrinthId', modrinthId); @@ -21,5 +20,12 @@ export const ModrinthOauthCallbackHandler = () => { const params = new URLSearchParams(window.location.search); if (!params.has('code')) return null; const ret = Object.fromEntries(params); - return Object.keys(ret).length ? ret : null; + + if (!Object.keys(ret).length) return null; + + const redirectUri = new URL(`${window.location.origin}${window.location.pathname}`); + redirectUri.searchParams.set('curseforgeSlug', params.get('curseforgeSlug')); + redirectUri.searchParams.set('modrinthId', params.get('modrinthId')); + + return { ...ret, redirectUri: redirectUri.toString() }; };