feat: added email verification check

This commit is contained in:
Kyle Gill
2019-06-05 16:07:40 -06:00
parent 667cbeb5f7
commit ae993e28d0
5 changed files with 81 additions and 6 deletions

View File

@@ -69,30 +69,37 @@ class App extends Component {
<Router style={{ height: "100%" }}> <Router style={{ height: "100%" }}>
<PrivateRoute <PrivateRoute
authed={authed} authed={authed}
authUser={propAuthUser}
path="/app/:year" path="/app/:year"
component={Year} component={Year}
exact exact
/> />
<PrivateRoute <PrivateRoute
authed={authed} authed={authed}
authUser={propAuthUser}
path="/app/:year/:month" path="/app/:year/:month"
component={Month} component={Month}
exact exact
/> />
<PrivateRoute <PrivateRoute
authed={authed} authed={authed}
authUser={propAuthUser}
emailVerificationUnnecessary={false}
path="/app/:year/:month/:day" path="/app/:year/:month/:day"
component={Day} component={Day}
exact exact
/> />
<PrivateRoute <PrivateRoute
authed={authed} authed={authed}
authUser={propAuthUser}
emailVerificationUnnecessary={false}
path="/app/search" path="/app/search"
component={Search} component={Search}
exact exact
/> />
<PrivateRoute <PrivateRoute
authed={authed} authed={authed}
authUser={propAuthUser}
path="/app/user" path="/app/user"
component={User} component={User}
exact exact

View File

@@ -1,13 +1,23 @@
import React from "react" import React from "react"
import { Redirect, Location } from "@reach/router" import { Redirect, Location } from "@reach/router"
import ResendNotice from "components/ResendNotice"
// when a user isn't logged in, force a redirect // when a user isn't logged in, force a redirect
const PrivateRoute = ({ component: Component, authed, ...rest }) => { const PrivateRoute = ({
component: Component,
authed,
authUser,
emailVerificationUnnecessary = true,
...rest
}) => {
return ( return (
<Location> <Location>
{({ location }) => {({ location }) =>
authed === true ? ( authed === true ? (
emailVerificationUnnecessary || authUser.emailVerified ? (
<Component {...rest} /> <Component {...rest} />
) : (
<ResendNotice />
)
) : ( ) : (
<Redirect to="/login" from={location.pathname} /> <Redirect to="/login" from={location.pathname} />
) )

View File

@@ -0,0 +1,43 @@
import React from "react"
import styled from "@emotion/styled"
import { withTheme } from "emotion-theming"
import { compose } from "recompose"
import { withFirebase } from "components/firebase"
import { Button } from "components/elements"
import Logo from "components/Logo"
const NoticeBlock = styled.footer`
margin-top: 30px;
padding: 30px 0px;
text-align: center;
color: ${props => props.theme.colors.secondary};
`
const ResendNotice = ({ theme, firebase }) => (
<NoticeBlock>
<div>
<Logo color={theme.colors.secondary} />
</div>
<div>
Looks like you haven't verified your email, please verify before using the
app
</div>
<div style={{ marginTop: 15 }}>
<Button
colors={theme.colors}
onClick={() => {
firebase.resendVerification()
}}
fontSize="small"
>
Resend Verification?
</Button>
</div>
</NoticeBlock>
)
export default compose(
withFirebase,
withTheme
)(ResendNotice)

View File

@@ -53,6 +53,9 @@ class Firebase {
window.location.replace("/login") window.location.replace("/login")
} }
// send email reset to email provided
resendVerification = () => this.auth.currentUser.sendEmailVerification()
// send email reset to email provided // send email reset to email provided
doPasswordReset = email => this.auth.sendPasswordResetEmail(email) doPasswordReset = email => this.auth.sendPasswordResetEmail(email)

View File

@@ -94,9 +94,21 @@ class User extends React.Component {
User: <ProfileSectionText>{authUser.email}</ProfileSectionText> User: <ProfileSectionText>{authUser.email}</ProfileSectionText>
<div> <div>
<ProfileSectionText style={{ fontWeight: 400 }}> <ProfileSectionText style={{ fontWeight: 400 }}>
{authUser.emailVerified {authUser.emailVerified ? (
? "Email has been verified" "Email has been verified"
: "Email not verified"} ) : (
<span>
Email not verified{" "}
<span
onClick={() => {
console.log("resent!")
firebase.resendVerification(authUser.email)
}}
>
Resend?
</span>
</span>
)}
</ProfileSectionText> </ProfileSectionText>
</div> </div>
</ProfileSectionHeader> </ProfileSectionHeader>