Additional cleanup & Modrinth OAuth support
This commit is contained in:
parent
ba796eea48
commit
338a1a5791
3 changed files with 17 additions and 7 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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', {
|
||||
|
|
|
|||
|
|
@ -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() };
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue