How to use Firebase Twitter Authentication with React Native?

前端 未结 2 581
自闭症患者
自闭症患者 2021-01-18 02:31

How to use Firebase Twitter Authentication with React Native?

I tried both of the code below in reference to https://www.firebase.com/docs/web/guide/login/twitter.ht

2条回答
  •  自闭症患者
    2021-01-18 02:48

    I hacked together a solution... I am certain there is a cleaner approach that can be used to get the job done, but you can build on what I have accomplished

    /**
    * 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 })
        });
    }
    

    See a full explanation here... https://github.com/aaronksaunders/rn-firebase-demo

提交回复
热议问题