@@ -11,6 +11,9 @@ const SignInPage = () => (
11
11
< div >
12
12
< h1 > SignIn</ h1 >
13
13
< SignInForm />
14
+ < SignInGoogle />
15
+ < SignInFacebook />
16
+ < SignInTwitter />
14
17
< PasswordForgetLink />
15
18
< SignUpLink />
16
19
</ div >
@@ -80,11 +83,167 @@ class SignInFormBase extends Component {
80
83
}
81
84
}
82
85
86
+ class SignInGoogleBase extends Component {
87
+ constructor ( props ) {
88
+ super ( props ) ;
89
+
90
+ this . state = { error : null } ;
91
+ }
92
+
93
+ onSubmit = event => {
94
+ this . props . firebase
95
+ . doSignInWithGoogle ( )
96
+ . then ( socialAuthUser => {
97
+ // Create a user in your Firebase Realtime Database too
98
+ this . props . firebase
99
+ . user ( socialAuthUser . user . uid )
100
+ . set ( {
101
+ username : socialAuthUser . user . displayName ,
102
+ email : socialAuthUser . user . email ,
103
+ roles : [ ] ,
104
+ } )
105
+ . then ( ( ) => {
106
+ this . setState ( { error : null } ) ;
107
+ this . props . history . push ( ROUTES . HOME ) ;
108
+ } )
109
+ . catch ( error => {
110
+ this . setState ( { error } ) ;
111
+ } ) ;
112
+ } )
113
+ . catch ( error => {
114
+ this . setState ( { error } ) ;
115
+ } ) ;
116
+
117
+ event . preventDefault ( ) ;
118
+ } ;
119
+
120
+ render ( ) {
121
+ const { error } = this . state ;
122
+
123
+ return (
124
+ < form onSubmit = { this . onSubmit } >
125
+ < button type = "submit" > Sign In with Google</ button >
126
+
127
+ { error && < p > { error . message } </ p > }
128
+ </ form >
129
+ ) ;
130
+ }
131
+ }
132
+
133
+ class SignInFacebookBase extends Component {
134
+ constructor ( props ) {
135
+ super ( props ) ;
136
+
137
+ this . state = { error : null } ;
138
+ }
139
+
140
+ onSubmit = event => {
141
+ this . props . firebase
142
+ . doSignInWithFacebook ( )
143
+ . then ( socialAuthUser => {
144
+ // Create a user in your Firebase Realtime Database too
145
+ this . props . firebase
146
+ . user ( socialAuthUser . user . uid )
147
+ . set ( {
148
+ username : socialAuthUser . additionalUserInfo . profile . name ,
149
+ email : socialAuthUser . additionalUserInfo . profile . email ,
150
+ roles : [ ] ,
151
+ } )
152
+ . then ( ( ) => {
153
+ this . setState ( { error : null } ) ;
154
+ this . props . history . push ( ROUTES . HOME ) ;
155
+ } )
156
+ . catch ( error => {
157
+ this . setState ( { error } ) ;
158
+ } ) ;
159
+ } )
160
+ . catch ( error => {
161
+ this . setState ( { error } ) ;
162
+ } ) ;
163
+
164
+ event . preventDefault ( ) ;
165
+ } ;
166
+
167
+ render ( ) {
168
+ const { error } = this . state ;
169
+
170
+ return (
171
+ < form onSubmit = { this . onSubmit } >
172
+ < button type = "submit" > Sign In with Facebook</ button >
173
+
174
+ { error && < p > { error . message } </ p > }
175
+ </ form >
176
+ ) ;
177
+ }
178
+ }
179
+
180
+ class SignInTwitterBase extends Component {
181
+ constructor ( props ) {
182
+ super ( props ) ;
183
+
184
+ this . state = { error : null } ;
185
+ }
186
+
187
+ onSubmit = event => {
188
+ this . props . firebase
189
+ . doSignInWithTwitter ( )
190
+ . then ( socialAuthUser => {
191
+ // Create a user in your Firebase Realtime Database too
192
+ this . props . firebase
193
+ . user ( socialAuthUser . user . uid )
194
+ . set ( {
195
+ username : socialAuthUser . additionalUserInfo . profile . name ,
196
+ email : socialAuthUser . additionalUserInfo . profile . email ,
197
+ roles : [ ] ,
198
+ } )
199
+ . then ( ( ) => {
200
+ this . setState ( { error : null } ) ;
201
+ this . props . history . push ( ROUTES . HOME ) ;
202
+ } )
203
+ . catch ( error => {
204
+ this . setState ( { error } ) ;
205
+ } ) ;
206
+ } )
207
+ . catch ( error => {
208
+ this . setState ( { error } ) ;
209
+ } ) ;
210
+
211
+ event . preventDefault ( ) ;
212
+ } ;
213
+
214
+ render ( ) {
215
+ const { error } = this . state ;
216
+
217
+ return (
218
+ < form onSubmit = { this . onSubmit } >
219
+ < button type = "submit" > Sign In with Twitter</ button >
220
+
221
+ { error && < p > { error . message } </ p > }
222
+ </ form >
223
+ ) ;
224
+ }
225
+ }
226
+
83
227
const SignInForm = compose (
84
228
withRouter ,
85
229
withFirebase ,
86
230
) ( SignInFormBase ) ;
87
231
232
+ const SignInGoogle = compose (
233
+ withRouter ,
234
+ withFirebase ,
235
+ ) ( SignInGoogleBase ) ;
236
+
237
+ const SignInFacebook = compose (
238
+ withRouter ,
239
+ withFirebase ,
240
+ ) ( SignInFacebookBase ) ;
241
+
242
+ const SignInTwitter = compose (
243
+ withRouter ,
244
+ withFirebase ,
245
+ ) ( SignInTwitterBase ) ;
246
+
88
247
export default SignInPage ;
89
248
90
- export { SignInForm } ;
249
+ export { SignInForm , SignInGoogle , SignInFacebook , SignInTwitter } ;
0 commit comments