Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glenngillen/verify flow #1124

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/components/Auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const Auth0 = new Auth0Client({
domain: publicRuntimeConfig.auth0.issuerBaseHost as string,
clientId: publicRuntimeConfig.auth0.clientId as string,
authorizationParams: {
scope: 'openid',
redirect_uri: `${publicRuntimeConfig.auth0.baseUrl}/auth/callback`,
},
});
Expand All @@ -38,6 +39,7 @@ const currentUser = async (): Promise<User | void> => {
const userId = window.sessionStorage.getItem('userId') as string | '';
const token = await Auth0.getTokenSilently({
authorizationParams: {
scope: 'openid',
audience,
},
});
Expand Down Expand Up @@ -128,6 +130,7 @@ const Auth: FunctionComponent<Props> = ({
const signin = useCallback(async (): Promise<void> => {
await Auth0.loginWithRedirect({
authorizationParams: {
scope: 'openid',
audience,
source: 'ockam-website',
},
Expand All @@ -137,6 +140,7 @@ const Auth: FunctionComponent<Props> = ({
const signup = useCallback(async (): Promise<void> => {
await Auth0.loginWithRedirect({
authorizationParams: {
scope: 'openid',
audience,
screen_hint: 'signup',
source: 'ockam-website',
Expand Down
13 changes: 9 additions & 4 deletions src/components/Signup/SignupFlowManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import MarketplaceSetup from './MarketplaceSetup';
import Notice from './Notice';
import UserDetails from './UserDetails';
import { TIERS } from '../Packaging/tiers';
import VerifyEmailModal from './VerifyEmail';

type Props = {
install: MDXRemoteSerializeResult;
Expand Down Expand Up @@ -63,6 +64,7 @@ const SignupFlowManager: FC<Props> = ({ install, terms }): ReactElement => {
const [marketplaceFulfilment, setMarketplacceFulfilment] = useState<boolean>(false);
const [returningDelegate, setReturningDelegate] = useState<boolean>(false);
const [completedDelegate, setCompletedDelegate] = useState<boolean>(false);
const [verifyEmail, setVerifyEmail] = useState<boolean>(false);

const [transitioning, setTransitioning] = useState(false);
// const [nextHidden, setNextHidden] = useState(false);
Expand Down Expand Up @@ -427,11 +429,13 @@ const SignupFlowManager: FC<Props> = ({ install, terms }): ReactElement => {
setIsLoaded(true);
}
} catch (error) {
setVerifyEmail(true);
if (error instanceof UnverifiedEmailError) {
setMessage('📨 Check your inbox! Verify your email address and then refresh this page');
setTimeout(() => {
router.reload();
}, 5000);
setVerifyEmail(true);
// setMessage('📨 Check your inbox! Verify your email address and then refresh this page');
// setTimeout(() => {
// router.reload();
// }, 5000);
} else {
console.error(error);
}
Expand All @@ -456,6 +460,7 @@ const SignupFlowManager: FC<Props> = ({ install, terms }): ReactElement => {
return (
<Flex mx="auto" pb="32" p={8} direction={{ base: 'row' }} w="100%">
{message && <Notice message={message} />}
<VerifyEmailModal open={verifyEmail} />
<Box style={{ transition: '200ms ease-in opacity', opacity: returningDelegate ? '0' : '1' }}>
<Steps
variant="circles"
Expand Down
59 changes: 59 additions & 0 deletions src/components/Signup/VerifyEmail.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { FC, useEffect } from 'react';
import {
Button,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
useDisclosure,
} from '@chakra-ui/react';
import { useRouter } from 'next/router';

type Props = {
open: boolean;
};
const VerifyEmailModal: FC<Props> = ({ open }) => {
const { isOpen, onOpen, onClose } = useDisclosure();
const router = useRouter();

const close = () => {
onClose();
router.reload();
};

useEffect(() => {
if (open) {
onOpen();
}
}, [open]);

return (
<Modal isOpen={isOpen} onClose={close}>
<ModalOverlay />
<ModalContent backgroundColor="brand.200">
<ModalHeader textAlign="center" fontSize={42}>
📬
</ModalHeader>
<ModalHeader textAlign="center" fontSize={32} letterSpacing="-1px">
Check your inbox!
</ModalHeader>
<ModalCloseButton />
<ModalBody>
Before you can proceed we need to confirm your email address. We&apos;ve already sent you
an email, just click the link in it and then come back here.
</ModalBody>

<ModalFooter>
<Button colorScheme="blue" mr={3} onClick={close}>
I&apos;ve verified
</Button>
</ModalFooter>
</ModalContent>
</Modal>
);
};

export default VerifyEmailModal;
Loading