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

add email verification #207

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions lumium-space/pages/auth/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import {
FormErrorMessage,
Image
} from '@chakra-ui/react';
import React, { useEffect, useRef, useState } from 'react';
import React, { useState } from 'react';
import { useApi } from "@hooks/api";
import Router from 'next/router';
import { ViewIcon, ViewOffIcon } from '@chakra-ui/icons';
import { AUTH_SIGNIN, AUTH_SIGNUP, EMAIL_EXISTS, ROOT, SPACES_NEW } from '@routes/space';
import { AUTH_SIGNIN, AUTH_SIGNUP, AUTH_VERIFY_EMAIL, EMAIL_EXISTS } from '@routes/space';
import Session from 'supertokens-auth-react/recipe/session';
import { useUserInfo } from '@hooks/api';
import { AuthBox } from '@components/auth/AuthBox';
Expand All @@ -46,7 +46,7 @@ const SignUp: React.FC = () => {
"value": password
}
]
}).then(() => Router.push(SPACES_NEW));
}).then(() => Router.push(AUTH_VERIFY_EMAIL));
} else {
setEmailExistsError(true);
};
Expand Down
48 changes: 48 additions & 0 deletions lumium-space/pages/auth/verify-email.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { InfoIcon } from "@chakra-ui/icons";
import { Box, Button, Fade, Heading, ScaleFade, Text } from "@chakra-ui/react";
import { Authenticator } from "@components/security/Authenticator";
import { useApi } from "@hooks/api";
import { EMAIL_VERIFY, EMAIL_VERIFY_TOKEN, SPACES_NEW } from "@routes/space";
import Router, { useRouter } from 'next/router';
import React, { useEffect, useState } from 'react'
export default function VerifyEmail() {
const [api] = useApi();
const router = useRouter();
const { token } = router.query;
const [resendIsShown, setResendIsShown] = useState(true);
if (token) {
api.post(EMAIL_VERIFY, {
"method": "token",
"token": token
}).then(() => Router.push(SPACES_NEW));
};
useEffect(() => {
api.get(EMAIL_VERIFY).then((promise) => promise.data).then((value) => {
if (value.isVerified) {
Router.push(SPACES_NEW);
};
});
}, [api])
const handleResendEmail = () => {
api.post(EMAIL_VERIFY_TOKEN);
setResendIsShown(false);
};
return (
<Authenticator>
<Box textAlign="center" py={10} px={6}>
<InfoIcon boxSize={'50px'} color={'blue.500'} />
<Heading as="h2" size="xl" mt={6} mb={2}>
Verify your E-Mail
</Heading>
<Text color={'gray.500'}>
Check your inbox to access Lumium
</Text>
<ScaleFade initialScale={0.9} in={resendIsShown}>
<Button onClick={handleResendEmail}>
Resend E-Mail
</Button>
</ScaleFade>
</Box>
</Authenticator>
)
}
12 changes: 10 additions & 2 deletions lumium-space/src/components/security/Authenticator.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import { AUTH_SIGNIN } from "@routes/space";
import { useApi } from "@hooks/api";
import { AUTH_SIGNIN, AUTH_VERIFY_EMAIL, EMAIL_VERIFY } from "@routes/space";
import Router from "next/router";
import { useEffect, useState } from "react";
import Session from 'supertokens-auth-react/recipe/session';

export const Authenticator: React.FC = (props) => {
const [api] = useApi();
const [loginStatus, setLoginStatus] = useState(false);
useEffect(() => {
Session.doesSessionExist().then((loggedIn) => {
setLoginStatus(loggedIn)
if (!loggedIn) {
Router.push(AUTH_SIGNIN)
} else {
api.get(EMAIL_VERIFY).then((promise) => promise.data).then((value) => {
if (!value.isVerified) {
Router.push(AUTH_VERIFY_EMAIL);
};
});
};
});
}, []);
}, [Session]);
return (
<>
{loginStatus && props.children}
Expand Down
1 change: 1 addition & 0 deletions routes/space/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const AUTH = ROOT + 'auth';
export const AUTH_SIGNIN = AUTH + '/signin';
export const AUTH_SIGNUP = AUTH + '/signup';
export const AUTH_PASSWORD_RESET = AUTH + '/reset-password';
export const AUTH_VERIFY_EMAIL = AUTH + '/verify-email';
export const SPACES = ROOT + 'spaces';
export const SPACES_NEW = SPACES + '/new';
export const SPACES_CREATE = SPACES + '/create';
Expand Down