Guest User

Untitled

a guest
Feb 21st, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. import firebase from 'firebase';
  2.  
  3. const config = {
  4. apiKey: 'API_KEY',
  5. authDomain: '****',
  6. databaseURL: '****',
  7. storageBucket: '****'
  8. };
  9.  
  10. firebase.initializeApp(config);
  11.  
  12.  
  13. // 中略
  14.  
  15.  
  16. const loginWithFb = () => {
  17. return Facebook.logInWithReadPermissionsAsync('APP_ID', {
  18. permissions: ['public_profile']
  19. });
  20. };
  21.  
  22. // ログインボタンのonPressにbind
  23. async onPress() {
  24. const { type, token } = await loginWithFb();
  25.  
  26. if (type === 'success') {
  27. const credential = firebase.auth.FacebookAuthProvider.credential(token);
  28.  
  29. firebase.auth().signInWithCredential(credential).catch((error) => {
  30. console.log(error);
  31. });
  32. }
  33. }
  34.  
  35. componentDidMount() {
  36. const auth = firebase.auth.FacebookAuthProvider;
  37. console.log(auth);
  38. // undefined
  39. }
  40.  
  41. // ちゃんと保存される
  42. firebase.database().ref('users/' + 1).set({
  43. name: 'hoge'
  44. });
  45.  
  46. // firebase_をチェーンに追加
  47. const credential = firebase.firebase_.auth.FacebookAuthProvider.credential(token);
  48.  
  49. firebase.auth().signInWithCredential(credential)
  50. firebase.auth().signOut();
Add Comment
Please, Sign In to add comment