2016-05-19 37 views
11

我正在嘗試使用Firebase和Electron。在安裝時就像我在網頁上一樣,它不起作用,因爲Electron頁面是本地託管的,沒有hostname。這是我得到的錯誤...與電子一起使用Firebase

Uncaught Error: This domain is not authorized for OAuth operations for your Firebase project. Edit the list of authorized domains from the Firebase console. 

我無法將一個空的(或通配符)授權域添加到Firebase控制檯,因此我被卡住了。有沒有人有任何想法來解決這個問題?

編輯:這是我使用的代碼,它僅僅是標準的樣板,沒有什麼多餘的......

<script src="https://www.gstatic.com/firebasejs/live/3.0/firebase.js"></script> 
<script> 
    var config = { 
    apiKey: "AIzaSyBvmmPB0_Oddc-02cUj3Ntt3wi8jSxxxx", 
    authDomain: "xxxxx-d24ad.firebaseapp.com", 
    databaseURL: "https://xxxxx-d24ad.firebaseio.com", 
    storageBucket: "", 
    }; 
    firebase.initializeApp(config); 
</script> 
+0

能否請您發佈的代碼片段?我不知道Firebase需要主機名。 – Charlie

+0

@Charlie,添加了一個代碼片段。 – DaveJ

+0

@Daveyjoe - 剛剛在這上面碰到了一堵牆,你知道是否有任何方法讓Electron從本地主機服務? – user1787531

回答

5

現在,你可以通過你的配置取出authDomain線抑制這種錯誤。 auth signInWithPopup/signInWithRedirect操作需要authDomain,但其他所有操作都應該有效。

僅當您實際嘗試執行signInWithPopup/Redirect時才引發此錯誤的庫版本正在實施中。

+0

非常好,謝謝!如果您可以在支持'signInWithPopup/Redirect'時回來編輯您的答案,那就太棒了。 – DaveJ

+0

對此有何更新? – DaveJ

1

我不知道這是不是最好的解決辦法,但是是一個解決辦法。

創建一個文件server.js用一個簡單的Express服務器

「server.js」

var express = require('express'); 
var http = require('http'); 
var path = require('path'); 

var appServer = express(); 
appServer.use(express.static(path.join(__dirname, ''))); 

appServer.get('*', (req, res) => { 
    res.sendFile(__dirname + 'index.html'); 
}); 

http.createServer(appServer).listen(3007, function() { 
    console.log('Express server listening on port'); 
}); 

在你main.js(電子主JS文件)

在在main.js頂部啓動節點服務器

require('./server'); 

並修改「win.loadURL」

win.loadURL('http://localhost:3007'); 

我叉你的項目和實現,從firebase的錯誤消失了,但jQuery沒有定義,我認爲你可以解決這個問題。

https://github.com/diegoddox/sad-electron-firebase-error

0

您可以使用手動登錄流程和firebase身份驗證方法使用firebase身份驗證的GitHub,Twitter,Facebook,Google Provider。

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

我創建有用的庫對於這些情況。

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)) 
相關問題