-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.android.js
80 lines (66 loc) · 3.05 KB
/
index.android.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
68
69
70
71
72
73
74
75
76
77
78
79
80
import React, { Component } from 'react';
import { AppRegistry, Text } from 'react-native';
import * as firebase from 'firebase';
const FBSDK = require('react-native-fbsdk');
const {
LoginButton,
AccessToken
} = FBSDK;
// Initialize Firebase
const firebaseConfig = {
apiKey: "AIzaSyDNxNYTT7Yk9-gPe7x8VOWD7pe22y8Mkp0",
authDomain: "choosy-app-2809a.firebaseapp.com",
databaseURL: "https://choosy-app-2809a.firebaseio.com",
//storageBucket: "<your-storage-bucket>"
};
const firebaseApp = firebase.initializeApp(firebaseConfig);
var provider = new firebase.auth.FacebookAuthProvider();
var accessToken;
var credential;
var errorCode;
class Choosy extends Component {
constructor(props) {
super(props);
}
render(){
setInterval(function(){console.log(errorCode);}, 3000);
return (
<LoginButton
publishPermissions={["publish_actions"]}
onLoginFinished={
(error, result) => {
if (error) {
alert("login has error: " + result.error);
} else if (result.isCancelled) {
alert("login is cancelled.");
} else {
AccessToken.getCurrentAccessToken().then(
(data) => {
alert(data.accessToken.toString());
accessToken = data.accessToken.toString();
credential = firebase.auth.FacebookAuthProvider.credential(accessToken);
firebase.auth().signInWithCredential(credential).catch(function(error) {
// Handle Errors here.
errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
if (errorCode === 'auth/account-exists-with-different-credential') {
alert('Email already associated with another account.');
// Handle account linking here, if using.
} else {
console.error(error);
}
});
}
)
}
}
}
onLogoutFinished={() => alert("logout.")}/>
);
}
};
AppRegistry.registerComponent('Choosy', () => Choosy);