@@ -10,6 +10,28 @@ import withFirebaseAuth, { WrappedComponentProps } from 'react-with-firebase-aut
10
10
import { store } from '../store.js'
11
11
import { compareJournals } from '../utils/utils.js'
12
12
13
+
14
+ function LoginButton ( props ) {
15
+ const dispatch = useDispatch ( ) ;
16
+ async function mySignIn ( ) {
17
+ props . providerFn ( ) . then ( ( result ) => {
18
+ // console.log('STOREATSIGNIN', store.getState())
19
+ const newId = result . user ?. uid ;
20
+
21
+ newId && dispatch ( { type : 'CREATE_USER_SUCCESS' , payload : newId } )
22
+ journalRef
23
+ . child ( newId )
24
+ . on ( 'value' , ( snapshot ) => {
25
+ compareJournals ( store . getState ( ) . journal , snapshot . val ( ) )
26
+ } )
27
+ } )
28
+ }
29
+ return (
30
+ < button onClick = { mySignIn } > Sign in with { props . providerName } </ button >
31
+ )
32
+ }
33
+
34
+ // I'll need these props later on I guess, in an abstracted login form ocmponent
13
35
function FbLogin ( {
14
36
/** These props are provided by withFirebaseAuth HOC */
15
37
signInWithEmailAndPassword,
@@ -29,43 +51,31 @@ import {compareJournals} from '../utils/utils.js'
29
51
const dispatch = useDispatch ( ) ;
30
52
//const user = useSelector(state => state.user);
31
53
32
- async function mySignIn ( ) {
33
- signInWithGoogle ( ) . then ( ( result ) => {
34
- // console.log('STOREATSIGNIN', store.getState())
35
- const newId = result . user ?. uid ;
36
-
37
- newId && dispatch ( { type : 'CREATE_USER_SUCCESS' , payload : newId } )
38
- journalRef
39
- . child ( newId )
40
- . on ( 'value' , ( snapshot ) => {
41
- compareJournals ( store . getState ( ) . journal , snapshot . val ( ) )
42
- } )
43
- } )
44
- }
45
-
46
54
async function mySignOut ( ) {
47
55
signOut ( )
48
56
dispatch ( { type : 'LOGOUT' } ) ;
49
57
50
58
}
59
+ // const providers = [[signInWithGoogle, "Google"],[signInWithEmailAndPassword, "Email"] ]
60
+
61
+ const providers = [ [ signInWithGoogle , "Google" ] ]
51
62
// useEffect (() => {
52
63
// console.log('GOTUSERID', user && user.uid)
53
64
// })
54
65
55
66
return (
67
+
56
68
< >
57
- {
58
- user
59
- ? < button className = "clear dark" href = "#" > Hello, { user . displayName } </ button >
60
- : < button onClick = { mySignIn } > Sign in with Google</ button >
69
+ { user ?
70
+ < >
71
+ < button className = "clear dark" href = "#" > Hello, { user . displayName } </ button >
72
+ < button className = "bg-dark text-light" onClick = { mySignOut } > Sign out</ button >
73
+ </ >
74
+ : providers . map ( ( [ p , n ] ) => < LoginButton key = { n } providerFn = { p } providerName = { n } /> )
61
75
}
62
- {
63
- user &&
64
- < button className = "bg-dark text-light" onClick = { mySignOut } > Sign out</ button >
65
- }
66
- </ > )
67
-
68
- }
76
+ </ >
77
+ )
78
+ }
69
79
70
80
export default withFirebaseAuth ( {
71
81
providers : providers ,
0 commit comments