Files
TheGame/packages/web/pages/join/guild/auth.tsx
dan13ram 8517a26048 Upgrade dependencies (#486)
* upgraded storybook dependencies

* upgraded web dependencies

* updated timezone selector

* upgrade chakra in metamaps

* upgraded react-dnd in metamaps

* upgraded framer-motion

* fixed types in metamaps

* upgraded eslint

* upgraded lerna, husky and graphql

* upgraded node version

* removed metamaps package

* fixed all eslint issues

* ran yarn format to prettier format all files

* updated lint-staged & husky scripts

* add executable perms to pre-push scripts

* updated yarn.lock

* fixed eslint and moved chakra icons to ds

* fixed emotion errors

* removed extra useContext

* update yarn.lock

* upgraded more packages

* removed unnecessary .huskyrc.json

* lint fix
2021-05-01 12:46:48 +05:30

50 lines
1.6 KiB
TypeScript

import { PageContainer } from 'components/Container';
import { useAuthenticateDiscordGuildMutation } from 'graphql/autogen/types';
import { useRouter } from 'next/router';
import React, { useEffect, useState } from 'react';
const GuildSetupAuthCallback: React.FC = () => {
const router = useRouter();
const [authGuildRes, authGuild] = useAuthenticateDiscordGuildMutation();
const [error, setError] = useState<string>('');
useEffect(() => {
// when auth request is denied, we get `error=access_denied` and `error_description` and `state` parameters
const { code, error_description: discordErrorDetail } = router.query;
if (discordErrorDetail != null) {
setError(discordErrorDetail as string);
}
const submitAuthCode = async () => {
const { data, error: mutationError } = await authGuild({
code: code as string,
});
const response = data?.authenticateDiscordGuild;
if (mutationError || response?.success === false) {
setError(mutationError?.message || 'An unexpected error occurred.');
} else if (response?.guildname != null) {
if (response?.exists === true) {
router.push(`/guild/${response?.guildname}`);
} else {
router.push(`/join/guild/${response?.guildname}`);
}
}
};
if (!error.length && code) {
submitAuthCode();
}
}, [router, authGuild, error]);
return (
<PageContainer>
{error && `Could not load your guild information from Discord. ${error}`}
{authGuildRes.fetching &&
'Loading your guild information from Discord...'}
</PageContainer>
);
};
export default GuildSetupAuthCallback;