質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Firebase

Firebaseは、Googleが提供するBasSサービスの一つ。リアルタイム通知可能、並びにアクセス制御ができるオブジェクトデータベース機能を備えます。さらに認証機能、アプリケーションのログ解析機能などの利用も可能です。

Google

Googleは、アメリカ合衆国に位置する、インターネット関連のサービスや製品を提供している企業です。検索エンジンからアプリケーションの提供まで、多岐にわたるサービスを提供しています。

Q&A

解決済

1回答

3873閲覧

firebaseでgoogleアカウントのログイン機能の実装ができない

GonbeeAudio

総合スコア9

Firebase

Firebaseは、Googleが提供するBasSサービスの一つ。リアルタイム通知可能、並びにアクセス制御ができるオブジェクトデータベース機能を備えます。さらに認証機能、アプリケーションのログ解析機能などの利用も可能です。

Google

Googleは、アメリカ合衆国に位置する、インターネット関連のサービスや製品を提供している企業です。検索エンジンからアプリケーションの提供まで、多岐にわたるサービスを提供しています。

0グッド

1クリップ

投稿2019/11/24 04:44

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

Firebase AuthenticationのJavaScriptが読み込まれていません。

HTML

1<script src="scripts/main.js"></script>

よりも前に以下のコードを追加してください。

HTML

1<script src="https://www.gstatic.com/firebasejs/7.5.0/firebase-auth.js"></script>

投稿2019/11/24 08:57

chika3742

総合スコア113

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問