-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathwithEmailVerification.js
67 lines (58 loc) · 1.81 KB
/
withEmailVerification.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import React from 'react';
import AuthUserContext from './context';
import { withFirebase } from '../Firebase';
const needsEmailVerification = authUser =>
authUser &&
!authUser.emailVerified &&
authUser.providerData
.map(provider => provider.providerId)
.includes('password');
const withEmailVerification = Component => {
class WithEmailVerification extends React.Component {
constructor(props) {
super(props);
this.state = { isSent: false };
}
onSendEmailVerification = () => {
this.props.firebase
.doSendEmailVerification()
.then(() => this.setState({ isSent: true }));
};
render() {
return (
<AuthUserContext.Consumer>
{authUser =>
needsEmailVerification(authUser) ? (
<div>
{this.state.isSent ? (
<p>
Email confirmation sent: check your Inbox (Spam
folder included) for a confirmation email.
Refresh this page once you confirmed your email.
</p>
) : (
<p>
Verify your email: check your Inbox (Spam folder
included) for a confirmation email or send
another confirmation email.
</p>
)}
<button
type="button"
onClick={this.onSendEmailVerification}
disabled={this.state.isSent}
>
Send confirmation email
</button>
</div>
) : (
<Component {...this.props} />
)
}
</AuthUserContext.Consumer>
);
}
}
return withFirebase(WithEmailVerification);
};
export default withEmailVerification;