Home>

firebase

I'm trying to add a function to log in with google authorization in firebase, but I'm having trouble getting an error.

Error message

main.js: 1 Uncaught TypeError: Cannot read property 'GoogleAuthProvider' of undefined
at

Applicable source code

"public/login.html"




login



https://firebase.google.com/docs/web/setup#available-libraries->



"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': '[email protected]'
});

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.
});# Tried
I disassembled and ported the firebase tutorial, compared it, and looked for similarities with other source code.

Supplemental information (FW/tool version etc.)

[email protected]
node.js v13.1.0