2015-06-12 7 views
8

प्रतिक्रिया मूल के साथ फ़ायरबेस ट्विटर प्रमाणीकरण का उपयोग कैसे करें?प्रतिक्रिया मूल के साथ फायरबेस ट्विटर प्रमाणीकरण का उपयोग कैसे करें?

मैं https://www.firebase.com/docs/web/guide/login/twitter.html

var Firebase = require("firebase"); 

var App = React.createClass({ 

    render: function() { 
    return (
     <View> 
     <Text onPress={this._handlePress}> 
      Twitter login 
     </Text> 
     </View> 
    ); 
    }, 

    _handlePress: function() { 
    var myApp = new Firebase("https://<myapp>.firebaseio.com"); 

    myApp.authWithOAuthRedirect("twitter", function(error) { 
     if (error) { 
     console.log("Login Failed!", error); 
     } else { 
     // We'll never get here, as the page will redirect on success. 
     } 
    }); 

    } 

}); 

और

var Firebase = require("firebase"); 

var App = React.createClass({ 

    render: function() { 
    return (
     <View> 
     <Text onPress={this._handlePress}> 
      Twitter login 
     </Text> 
     </View> 
    ); 
    }, 

    _handlePress: function() { 
    var myApp = new Firebase("https://<myapp>.firebaseio.com"); 

    myApp.authWithOAuthPopup("twitter", function(error, authData) { 
     if (error) { 
     console.log("Login Failed!", error); 
     } else { 
     console.log("Authenticated successfully with payload:", authData); 
     } 
    }); 

    } 

}); 

जब मैं authWithOAuthRedirect का उपयोग करने के संदर्भ में नीचे दिए गए कोड के दोनों की कोशिश की, एक त्रुटि

undefined is not an object (evaluating 'window.location.href') 

की तरह हुआ जब मैं authWithOAuthPopup का उपयोग , कुछ नहीं हुआ।

मैं इस प्रश्न को कैसे हल कर सकता हूं? या यह संभव नहीं है?

उत्तर

3

यह वेब के लिए फ़ायरबेस ट्विटर एकीकरण है। अपने पूर्वजों और जावास्क्रिप्ट के उपयोग के बावजूद, प्रतिक्रिया मूल वेब पर किसी भी तरह से नहीं है; आपके पास डोम नहीं है, आपके पास ब्राउज़र नहीं है और इसलिए आपके पास वर्तमान विंडो को रीडायरेक्ट करने की क्षमता नहीं है, जो ऐसा लगता है कि यह कोड क्या करने का प्रयास कर रहा है।

तो, इस पुस्तकालय का उपयोग करके, अपने प्रश्न का उत्तर देने के लिए, यह संभव नहीं होगा। आपको लगता है कि ब्राउज़र-स्टाइल प्रवाह का उपयोग किए बिना आप जो करना चाहते हैं उसे करने के लिए आपको ओब्जे-सी में एक एक्सटेंशन लिखना होगा।

+0

उस अंतिम बिंदु पर, आईओएस के लिए फायरबेस लॉगिन डेमो शुरू करने के लिए एक अच्छी जगह हो सकती है: https://github.com/firebase/login-demo-ios लेकिन यह नहीं होगा दिल में बेहोश –

+0

आपकी मदद के लिए धन्यवाद। मैंने प्रतिक्रिया मूल का उपयोग करना बंद कर दिया और आयनिक का उपयोग करने की कोशिश की। – okmttdhr

+0

@ फ्रैंकवन पफेलन क्या यह ईमेल/पीडब्ल्यू ऑथ के साथ-साथ फायरबेस के साथ प्रतिक्रियात्मक मूल पर भी सच है? –

1

मैं एक साथ एक समाधान काट दिया ... मैं कुछ वहाँ एक क्लीनर दृष्टिकोण है कि काम किया पाने के लिए इस्तेमाल किया जा सकता है, लेकिन आप का निर्माण कर सकते पर मैं क्या पूरा किया है

/** 
* login in the user with the credentials, gets the whole process 
* started, [NOTE] probably can just construct the url myself? 
*/ 
_doGitHubLogin() { 
    this.props.fbRef.authWithOAuthRedirect("github", function (error) { 
     if (error) { 
      console.log("Authentication Failed!", error); 
     } else { 
      console.log("Authenticated successfully with payload:", authData); 
     } 
    }); 
} 

componentDidMount() { 

    // set this interval to check for me trying to redirect the window... 
    var that = this 
    that.inter = setInterval(function() { 
     if (window.location && window.location.split) { 

      // set the redirect on the url.. 
      var newLocation = window.location.split("redirectTo=null")[0] 
      newLocation = newLocation + "redirectTo=https://auth.firebase.com/v2/clearlyinnovative-firebasestarterapp/auth/github/callback" 

      // open the browser... 
      that.setState({ url: newLocation }) 

      // clear the interval to stop waiting for the location to be set.. 
      clearInterval(that.inter) 
     } 
    }, 3000); 


    this.props.fbRef.onAuth((_auth) => { 
     console.log(_auth) 
     this.setState({ auth: _auth }) 
    }); 
} 

पूर्ण ब्यौरा देखने यहां ... https://github.com/aaronksaunders/rn-firebase-demo

संबंधित मुद्दे