Using Firebase with Electron

后端 未结 4 690
生来不讨喜
生来不讨喜 2020-12-28 08:44

I\'m trying to use Firebase with Electron. When installing it just like I would on a web page it doesn\'t work because Electron pages are hosted locally and don\'t have a

4条回答
  •  一向
    一向 (楼主)
    2020-12-28 09:24

    You can use firebase auth's GitHub, Twitter, Facebook, Google Provider with electron by using the manual sign in flow and firebase auth signInWithCredential method.

    https://firebase.google.com/docs/auth/web/github-auth#handle_the_sign-in_flow_manually

    I created useful library for these case.

    https://github.com/mironal/electron-oauth-helper#firebase-auth-integration

    // Github manually flow example.
    
    const { OAuth2Provider } = require("electron-oauth-helper")
    
    const config = { /* oauth config. please see example/main/config.example.js.  */}
    const provider = new OAuth2Provider(config)
    provider.perform()
      .then(resp => {
        const query = querystring.parse(resp)
        const credential = firebase.auth.GithubAuthProvider.credential(query.access_token)
        firebase.auth().signInWithCredential(credential)
        .then(user => {
            console.log(user)
        })
        .catch(error => console.error(error))
      })
      .catch(error => console.error(error))
    

提交回复
热议问题