2016-07-22 4 views
0

이 코드가 실행되지 않는 이유를 잘 모릅니다. Firebase에서 필요한 모든 스 니펫을 복사하고 내 버튼이 실행 중입니다. 무엇이 잘못 될 수 있는지에 대한 아이디어가 있습니까? Github은 내가 여기서 여기에 더 많은 것들을 쓸 수있게 만들고있다.Firebase 인증

감사합니다.

<head> 
    <meta charset=utf-8 /> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <title>Auth</title> 
    <script src="https://www.gstatic.com/firebasejs/3.1.0/firebase.js"></script> 
    <script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-app.js"></script> 
    <script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-auth.js"></script> 
    <script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-database.js"></script> 
</head> 

<body> 

    <button onclick="googleAuth()">SIGN UP</button> 

<script> 

    var provider = new firebase.auth.GoogleAuthProvider(); 

    var googleAuth = function() { 
    console.log(firebase); 
    firebase.auth().signInWithPopup(provider).then(function(result) { 
     // This gives you a Google Access Token. You can use it to access the Google API. 
     var token = result.credential.accessToken; 
     // The signed-in user info. 
     var user = result.user; 
     // ... 
    }).catch(function(error) { 
     // Handle Errors here. 
     var errorCode = error.code; 
     var errorMessage = error.message; 
     // The email of the user's account used. 
     var email = error.email; 
     // The firebase.auth.AuthCredential type that was used. 
     var credential = error.credential; 
     // ... 
    }); 
}; 


</script> 








    <script> 
    // Initialize Firebase 
    var config = { 
     apiKey: "AIzaSyBeJIaAAD5-vK0kBDTRH6Y6_1ByVE3erJY", 
     authDomain: "fir-chat-d28be.firebaseapp.com", 
     databaseURL: "https://fir-chat-d28be.firebaseio.com", 
     storageBucket: "fir-chat-d28be.appspot.com", 
    }; 
    firebase.initializeApp(config); 
    </script> 

</body> 

답변

2

당신은 로그의 지시에 따라야합니다 : 그것은 signInWithPopup는 중포 기지 콘솔에서 추가 도메인없이 작동하지 않습니다 말한다 방법을 참조하십시오

The current domain is not authorized for OAuth operations. This will prevent signInWithPopup, signInWithRedirect, linkWithPopup and linkWithRedirect from working. Add your domain to the OAuth redirect domains list in the Firebase console -> Auth section -> Sign in method tab. 

+0

브라우저에서 html 파일을보고 있으므로 firebase에 도메인을 추가 할 수 없습니다. 콘솔에서도 오류가 발생하지 않았습니다. – maxwellgover

+0

브라우저에서 도메인이 무엇입니까? – Angelo

+0

file : /// C : /Users/MGover/Desktop/index.html – maxwellgover

0

코드는 좋아 보인다,하지만 당신은 HTML 파일로, 다음과 유사한 오류가 발생합니다 것을 실행하면 위치를 "이 작업이 응용 프로그램이 실행됩니다. 환경에서 지원되지 않습니다." 프로토콜은 "http 또는 https 여야합니다".

Firebase Hosting 기능을 활용 해 보시기 바랍니다. HTML, CSS, JavaScript 등 앱의 정적 애셋을 손쉽게 배포하고 호스팅 할 수 있습니다. 또한 무료입니다.

0

내 경험으로는 (단지 조언을 위해) firebase auth를 google이나 facebook과 같은 공급자와 함께 사용하지 마십시오. 더 나은 보안을 위해 전자 메일 및 암호 인증을 사용하십시오. 당신은 이해하기 쉬운 FirebaseUi, verry를 사용할 수 있으며, 원할 경우 복사하여 붙여 넣을 수 있습니다. Google 인증을 사용하는 경우 Google 계정을 가진 모든 사용자는 앱에 액세스하고 읽고 쓰고 삭제하고 업데이트 할 수 있습니다. 단, 파이어베이스 규칙에 대한 더 나은 경험은 있습니다.