@@ -4,6 +4,7 @@ import {StyleSheet, View, KeyboardAvoidingView} from 'react-native';
4
4
import { Grid , Row , Col } from 'react-native-easy-grid' ;
5
5
import { Text , H1 , Container , Content , Button , Card , CardItem , Body , Form , Item , Label , Input , Icon } from 'native-base' ;
6
6
7
+
7
8
class Login extends React . Component {
8
9
constructor ( ) {
9
10
super ( ) ;
@@ -22,10 +23,43 @@ class Login extends React.Component {
22
23
}
23
24
24
25
setShowLogin = ( ) => {
25
- this . setState ( { showLogin :true } ) ;
26
+ this . setState ( { showLogin :true } ) ;
26
27
}
27
-
28
- render ( ) {
28
+
29
+ fbLogin = ( ) => {
30
+ firebase . initializeApp ( firebaseConfig ) ;
31
+
32
+ firebase . auth ( ) . onAuthStateChanged ( ( user ) => {
33
+ if ( user != null ) {
34
+ console . log ( "We are authenticated now!" ) ;
35
+ }
36
+
37
+ // Do other things
38
+ } ) ;
39
+
40
+ async function loginWithFacebook ( ) {
41
+ const { type, token } = await Expo . Facebook . logInWithReadPermissionsAsync (
42
+ '<2074407626180948>' ,
43
+ { permissions : [ 'public_profile' ] }
44
+ ) ;
45
+
46
+ if ( type === 'success' ) {
47
+ const credential = firebase . auth . FacebookAuthProvider . credential ( token ) ;
48
+
49
+ firebase . auth ( ) . signInWithCredential ( credential ) . catch ( ( error ) => {
50
+ // Handle Errors here.
51
+ } ) ;
52
+ }
53
+ } }
54
+
55
+ fbLogout = ( ) => {
56
+ firebase . auth ( ) . signOut ( ) . then ( function ( ) {
57
+ } ) . catch ( function ( error ) {
58
+ // An error happened.
59
+ } ) ;
60
+ }
61
+
62
+ render ( ) {
29
63
return (
30
64
< KeyboardAvoidingView keyboardVerticalOffset = { - 64 } behavior = 'padding' style = { styles . container } >
31
65
@@ -58,10 +92,14 @@ class Login extends React.Component {
58
92
< View style = { { height :20 } } />
59
93
60
94
{ ( this . state . showLogin ) ?
61
- < Button full success style = { { marginLeft :15 , marginRight :15 } } onPress = { this . props . update } > < Text > Log In </ Text > </ Button >
95
+ < Button full success style = { { marginLeft :15 , marginRight :15 } } onPress = { this . props . update } > < Text > Login </ Text > </ Button >
62
96
:null }
63
97
< View style = { { height :10 } } />
64
- < Button full primary style = { { marginLeft :15 , marginRight :15 } } onPress = { this . handleSignup } > < Text > Sign Up</ Text > </ Button >
98
+ < Button full primary style = { { marginLeft :15 , marginRight :15 } } onPress = { this . handleSignup } > < Text > Signup</ Text > </ Button >
99
+ < View style = { { height :10 } } />
100
+ < Button full primary style = { { marginLeft :15 , marginRight :15 } } onPress = { this . fbLogin } > < Text > Login with Facebook</ Text > </ Button >
101
+ < View style = { { height :10 } } />
102
+ < Button full primary style = { { marginLeft :15 , marginRight :15 } } onPress = { this . fbLogout } > < Text > Logout</ Text > </ Button >
65
103
</ Form >
66
104
67
105
</ KeyboardAvoidingView >
@@ -102,4 +140,4 @@ export default connect(
102
140
}
103
141
}
104
142
105
- ) ( Login ) ;
143
+ ) ( Login ) ;
0 commit comments