Firebase:未捕获的语法错误:无效或意外的令牌 -> 未捕获的引用错误

亨里克

在我的网络应用程序中,我正在实施 Firebase 的 Google 登录授权,但看到SyntaxError网站加载和referenceError按钮onclick

在此处输入图片说明

我的 html 代码包括一个登录按钮和 Firebase 脚本:

<button onclick="login()">Sign In</button>

  <script src="https://www.gstatic.com/firebasejs/7.17.1/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.17.1/firebase-analytics.js"></script>
  <script src="https://www.gstatic.com/firebasejs/7.17.1/firebase-auth.js"></script>
  ​

我已经删除了下面的特定键和 Id 以使问题更笼统,但它们正确地绑定到 Firebase 项目。

  <script>
    // Your web app's Firebase configuration
    var firebaseConfig = {
      apiKey: "key",
      authDomain: "mywebsite.firebaseapp.com",
      databaseURL: "https://mywebsite.firebaseio.com",
      projectId: "signup",
      storageBucket: "signup.appspot.com",
      messagingSenderId: "senderId",
      appId: "appId",
      measurementId: "measureId"
    };
    // Initialize Firebase
    firebase.initializeApp(firebaseConfig);
    firebase.analytics();
  </script>

我正在链接到一个 JS 文件google_sign_in.js(这是我文件结构中的正确路径)

<script src="../static/js/google_sign_in.js" type="text/javascript"></script>

我的 google_sign_in.js 代码如下:

firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    // User is signed in.
    console.log("user signed in")​​
  } else {
    // No user is signed in.
    console.log("user signed out")
  }
});​​
var provider = new firebase.auth.GoogleAuthProvider();​
function login() {
  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;
    // ...
  });
}​
// sign signOut
function signOut() {
  // Sign out of Firebase.
  firebase.auth().signOut();
}​
var user = firebase.auth().currentUser;​
if (user != null) {
  user.providerData.forEach(function(profile) {
    console.log("Sign-in provider: " + profile.providerId);
    console.log("  Provider-specific UID: " + profile.uid);
    console.log("  Name: " + profile.displayName);
    console.log("  Email: " + profile.email);
    console.log("  Photo URL: " + profile.photoURL);
  });
}

更新 - 新的 javascript 代码和 devtools 的错误截图:

firebase.auth().onAuthStateChanged(function(user) {
  if (user) { // User is signed in.
    console.log("user signed in")
  } else {
    // No user is signed in.
    console.log("user signed out")
  }
});
var provider = new firebase.auth.GoogleAuthProvider();

function login() {
  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;
    // ...
  });
} // sign signOut
function signOut() {
  // Sign out of Firebase.
  firebase.auth().signOut();
}
var user = firebase.auth().currentUser;
if (user != null) {
  user.providerData.forEach(function(profile) {
    console.log("Sign-in provider: " + profile.providerId);
    console.log("  Provider-specific UID: " + profile.uid);
    console.log("  Name: " + profile.displayName);
    console.log("  Email: " + profile.email);
    console.log("  Photo URL: " + profile.photoURL);
  });
}

在此处输入图片说明

盖凡

好吧,这是一个艰难的...

您的代码中有一些偷偷摸摸的隐藏字符(\u200b- 零宽度空间),可能是由于从网页复制和粘贴。

使用文本编辑器中的箭头键,您将看到光标跳过这些。删除它们。

隐形字符

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

未捕获的语法错误:无效或意外的令牌。引用问题?

jQuery:未捕获的语法错误:无效或意外的令牌

未捕获的语法错误意外令牌

未捕获的语法错误意外令牌

未捕获的语法错误;意外的令牌 <

遍历JSON数组:未捕获的语法错误,未捕获的引用错误

Firefox与Chrome未捕获的语法错误意外的令牌错误

我在 Node.js 中收到以下错误“未捕获的语法错误:无效或意外的令牌”

无法解决未捕获的引用错误

angular2:未捕获的语法错误:意外的令牌<

JSON解析:未捕获的语法错误:意外的令牌e

Webpack未捕获的语法错误:意外的令牌<

ReactJS:未捕获的语法错误:意外的令牌(

Chrome未捕获的语法错误:意外的令牌非法

如何修复“未捕获的语法错误:意外的令牌导入”?

“未捕获的语法错误:意外的令牌o”

javascript json未捕获的语法错误意外的令牌非法

未捕获的语法错误:意外的令牌 { 函数 js

ScriptResource.axd 未捕获的语法错误:无效或意外的令牌

Rails 视图中的 JQuery append() 给出“未捕获的语法错误:无效或意外的令牌”

未捕获的语法错误:发送参数时令牌无效或意外

数据的查询选择器 - 未捕获的语法错误:无效或意外的令牌

cartItem.innerHTML ="这一行显示未捕获的语法错误:无效或意外的令牌

使用多个选择器时,未捕获的语法错误:无效或意外的令牌

Firebase:未捕获的语法错误:意外的标识符

未捕获的语法错误:“意外的标记 {”

未捕获的语法错误:意外的标记“!”

未捕获的语法错误:意外的标记“<”

React.scala 中的 ScalaJSReact 未捕获的引用错误