Equicord/src/equicordplugins/songSpotlight.desktop/lib/oauth2.tsx
nexpid df890ac455
SongSpotlight: Show off songs on your profile (#853)
* feat(SongSpotlight): port from vencord PR

* feat(SongSpotlight): some slight code improvements

* fix(components): match Link's props with vencord

* fix(SongSpotlight): ditch React.memo & csp
2026-03-02 11:06:18 -05:00

46 lines
1.6 KiB
TypeScript

/*
* Vencord, a Discord client mod
* Copyright (c) 2026 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { openModal } from "@utils/modal";
import { ApplicationIntegrationType } from "@vencord/discord-types/enums";
import { OAuth2AuthorizeModal, showToast, Toasts } from "@webpack/common";
import { apiConstants, authFetch, getData } from "./api";
import { useAuthorizationStore } from "./stores/AuthorizationStore";
import { logger } from "./utils";
export function presentOAuth2Modal() {
openModal(props => (
<OAuth2AuthorizeModal
{...props}
clientId={apiConstants.oauth2.clientId}
scopes={["applications.commands", "identify"]}
integrationType={ApplicationIntegrationType.USER_INSTALL}
permissions={0n}
responseType="code"
redirectUri={apiConstants.oauth2.redirectURL}
cancelCompletesFlow={false}
callback={async ({ location }) => {
if (!location) return;
try {
const url = new URL(location);
url.searchParams.append("whois", "equicord");
const token = await (await authFetch(url))?.text();
if (!token) return;
useAuthorizationStore.getState().setToken(token);
getData();
showToast("Successfully authorized!", Toasts.Type.SUCCESS);
} catch (error) {
logger.error("Got an error during OAuth2", error);
}
}}
/>
));
}