firebase
firebaseでgoogle承認でログインする機能を付けようとしているのですがエラーがでて困ってます。
発生している問題・エラーメッセージ
main.js:1 Uncaught TypeError: Cannot read property 'GoogleAuthProvider' of undefined
at
該当のソースコード
"public/login.html"
<html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width"> <title>login</title> </head> <body> <input type="button" value="sign-in" class="signInWithPopup"> <!-- The core Firebase JS SDK is always required and must be listed first --> <script src="https://www.gstatic.com/firebasejs/7.5.0/firebase-app.js"></script> <!-- TODO: Add SDKs for Firebase products that you want to use https://firebase.google.com/docs/web/setup#available-libraries --> <script src="https://www.gstatic.com/firebasejs/7.5.0/firebase-analytics.js"></script> <script> // Your web app's Firebase configuration var firebaseConfig = { apiKey: "AIzaSyBkjcTA1tUCMJnVdJS5cVg9-qmTBw18lic", authDomain: "myportfolio-317e7.firebaseapp.com", databaseURL: "https://myportfolio-317e7.firebaseio.com", projectId: "myportfolio-317e7", storageBucket: "myportfolio-317e7.appspot.com", messagingSenderId: "375192101524", appId: "1:375192101524:web:3b0efdc0db08abdf908a81", measurementId: "G-BHLD6F7P9R" }; // Initialize Firebase firebase.initializeApp(firebaseConfig); firebase.analytics(); </script> <!-- Insert these scripts at the bottom of the HTML, but before you use any Firebase services --> <script src="scripts/main.js"></script> </body> </html>"public/scripts/main.js"
var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('https://www.googleapis.com/auth/contacts.readonly');
firebase.auth().languageCode = 'pt';
// To apply the default browser preference instead of explicitly setting it.
// firebase.auth().useDeviceLanguage();
provider.setCustomParameters({
'login_hint': 'user@example.com'
});
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;
// ...
});
firebase.auth().signInWithRedirect(provider);
firebase.auth().getRedirectResult().then(function(result) {
if (result.credential) {
// 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;
// ...
});
firebase.auth().signOut().then(function() {
// Sign-out successful.
}).catch(function(error) {
// An error happened.
});# 試したこと
firebaseチュートリアルを分解して移植したり、見比べたり、他のソースコードと相似点を探したりしました。
補足情報(FW/ツールのバージョンなど)
firebase@7.5.0
node.js v13.1.0
回答1件
あなたの回答
tips
プレビュー