Skip to content

Commit e70358a

Browse files
committed
Adding Facebook Authentication
1 parent 5210ce7 commit e70358a

File tree

6 files changed

+11666
-231
lines changed

6 files changed

+11666
-231
lines changed

Diff for: backend/firebase/database.rules.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"rules": {
3-
".read": "auth != null",
4-
".write": "auth != null"
3+
".read": true,
4+
".write": true
55
}
66
}

Diff for: backend/jsonData/Rating.json

-109
This file was deleted.

Diff for: frontend/components/FoodCalorie.json

-114
This file was deleted.

Diff for: frontend/components/Login.js

+44-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {StyleSheet, View, KeyboardAvoidingView} from 'react-native';
44
import {Grid, Row, Col} from 'react-native-easy-grid';
55
import {Text, H1, Container, Content, Button, Card, CardItem, Body, Form, Item, Label, Input, Icon} from 'native-base';
66

7+
78
class Login extends React.Component {
89
constructor(){
910
super();
@@ -22,10 +23,43 @@ class Login extends React.Component {
2223
}
2324

2425
setShowLogin=() => {
25-
this.setState({showLogin:true});
26+
this.setState({showLogin:true});
2627
}
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() {
2963
return (
3064
<KeyboardAvoidingView keyboardVerticalOffset={-64} behavior='padding' style={styles.container}>
3165

@@ -58,10 +92,14 @@ class Login extends React.Component {
5892
<View style={{height:20}}/>
5993

6094
{(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>
6296
:null}
6397
<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>
65103
</Form>
66104

67105
</KeyboardAvoidingView>
@@ -102,4 +140,4 @@ export default connect(
102140
}
103141
}
104142

105-
)(Login);
143+
)(Login);

Diff for: frontend/firebase.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
3+
import * as firebase from 'firebase';
4+
5+
const firebaseConfig = {
6+
apiKey: "AIzaSyBmErNRB_6zuLdf-MTk03Fa0i1Dx5S-ltM ",
7+
authDomain: "snapdiet-alpha.firebaseapp.com",
8+
databaseURL: "https://snapdiet-alpha.firebaseio.com",
9+
storageBucket: "snapdiet-alpha.appspot.com"
10+
};
11+
12+
firebase.initializeApp(firebaseConfig);
13+
14+

0 commit comments

Comments
 (0)