diff --git a/src/components/Dialog/DiscordServerVerificationPopup.tsx b/src/components/Dialog/DiscordServerVerificationPopup.tsx index c9676a3..016a32f 100644 --- a/src/components/Dialog/DiscordServerVerificationPopup.tsx +++ b/src/components/Dialog/DiscordServerVerificationPopup.tsx @@ -1,7 +1,7 @@ import { useSelector } from "react-redux"; import { useForm, Controller } from "react-hook-form"; import { useAppDispatch } from "@store/store.model"; -import { useOAuth, useOAuthSocials } from "@components/Oauth2/oauth2"; +import { useOAuthSocials } from "@components/Oauth2/oauth2"; import { getServerDetails, useVerifyGuildOwnershipMutation diff --git a/src/components/Oauth2/oauth2.tsx b/src/components/Oauth2/oauth2.tsx index a32231b..4558ba9 100644 --- a/src/components/Oauth2/oauth2.tsx +++ b/src/components/Oauth2/oauth2.tsx @@ -32,76 +32,6 @@ const xCleanUp = (xIntervalRef) => { } }; -export const useOAuth = () => { - const [authenticating, setAuthenticating] = useState(false); - const [finsihedFlow, setFinishedFlow] = useState(false); - const popupRef = useRef(); - const intervalRef = useRef>(); - - const getAuth = useCallback(async (onSuccess, onFailure) => { - setAuthenticating(true); - if (popupRef.current && !popupRef.current.closed) { - popupRef.current.close(); - } - - const callbackUrl = encodeURI(`${window.location.origin}/callback`); - popupRef.current = openPopup( - `https://discord.com/oauth2/authorize?response_type=code&client_id=1080508975780474900&scope=guilds&state=15773059ghq9183habn&redirect_uri=${callbackUrl}&prompt=consent` - ) as any; - - async function handleMessageListener(message) { - try { - const type = message && message.data && message.data.type; - if (type === "OAUTH_RESPONSE") { - console.log("RECEIVE MESSAGE"); - const error = message && message.data && message.data.error; - if (error) { - onFailure(error); - } else { - const response = await axios.post( - `${environment.apiUrl}/aut/config/oauth2AccessToken`, - { - code: message.data.payload.code, - callbackUrl - } - ); - setAuthenticating(false); - clearInterval(intervalRef.current); - popupRef.current.close(); - onSuccess(response.data); - cleanup(intervalRef, popupRef, handleMessageListener); - } - } - } catch (genericError) { - onFailure(genericError); - console.error(genericError); - } - } - window.addEventListener("message", handleMessageListener); - - //Check for abrupt closing of popup - intervalRef.current = setInterval(() => { - const popupClosed = - !popupRef.current || - !(popupRef.current as any).window || - (popupRef.current as any).window.closed; - if (popupClosed) { - setAuthenticating(false); - clearInterval(intervalRef.current); - window.removeEventListener("message", handleMessageListener); - onFailure(); - } - }, 550); - - return () => { - setAuthenticating(false); - cleanup(intervalRef, popupRef, handleMessageListener); - }; - }, []); - - return { getAuth, authenticating }; -}; - export const useOAuthSocials = () => { const [authenticating, setAuthenticating] = useState(false); const [finsihedFlow, setFinishedFlow] = useState(false); @@ -128,6 +58,8 @@ export const useOAuthSocials = () => { if (error) { onFailure(error); } else { + // eslint-disable-next-line no-debugger + debugger; const response = await axios.post( `${environment.apiUrl}/aut/config/oauth2AccessTokenDiscord`, { diff --git a/src/pages/Oauth2Callback/Callback.tsx b/src/pages/Oauth2Callback/Callback.tsx index 9628b7f..fc54dd7 100644 --- a/src/pages/Oauth2Callback/Callback.tsx +++ b/src/pages/Oauth2Callback/Callback.tsx @@ -8,6 +8,8 @@ const queryToObject = (query) => { const Callback = () => { useEffect(() => { + // eslint-disable-next-line no-debugger + debugger; const payload = queryToObject(window.location.search.split("?")[1]); const error = payload && payload.error; if (!window.opener && !error) {