Firebase Cloud Messaging:请求缺少必需的身份验证凭证 [英] Firebase Cloud Messaging : Request is missing required Authentication Credentials

查看:84
本文介绍了Firebase Cloud Messaging:请求缺少必需的身份验证凭证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力让Firebase Cloud Messaging SDK与Nuxt JS一起使用

I'm struggling to get Firebase Cloud Messaging sdk to work with Nuxt JS

我不断得到检索令牌时发生错误.FirebaseError:消息传递:将用户订阅到FCM时发生问题:请求缺少必需的身份验证凭据.预期的OAuth 2访问令牌,登录cookie或其他有效的身份验证凭据."

I keep getting " An error occurred while retrieving token. FirebaseError: Messaging: A problem occured while subscribing the user to FCM: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. "

这是我作为nuxt.config.js中的一个插件运行的fcm.js中的代码

This is my code in the fcm.js which I'm running as a plugin in nuxt.config.js

import firebase from "../firebase/init";

firebase
  .messaging()
  .usePublicVapidKey(
    "BDYE2EYHdIp8qHjTKcJYPvO4PgaAH2pSruP55FOtNs5jWsgdeg7YK6OgJ0daSu21kN7aSzU19NRXRqC4bfITZYQ "
  );

firebase
  .messaging()
  .getToken()
  .then((currentToken) => {
    console.log(currentToken);
    if (currentToken) {
      sendTokenToServer(currentToken);
      updateUIForPushEnabled(currentToken);
    } else {
      // Show permission request.
      console.log(
        "No Instance ID token available. Request permission to generate one."
      );
      // Show permission UI.
      updateUIForPushPermissionRequired();
      setTokenSentToServer(false);
    }
  })
  .catch((err) => {
    console.log("An error occurred while retrieving token. ", err);
    showToken("Error retrieving Instance ID token. ", err);
    setTokenSentToServer(false);
  });

同时,如果您想知道用户是否已通过身份验证.该用户肯定已通过身份验证,因为我可以访问受保护的页面中的Firestore数据和路由,并且可以在vuex存储中看到UID详细信息.所以那边没有问题.我也尝试过删除usePublicVapidKey()行,它也行不通.

At the same time, if you are wondering if the user is authenticated. The user is definitely authenticated because I am able to access firestore data and access routes in my pages that I've guarded and I can see the UID details in my vuex store. So that side has no issue. I've also tried removing the usePublicVapidKey() line and it also doesn't work.

谢谢.

推荐答案

发现问题

firebase
  .messaging()
  .usePublicVapidKey(
    "BDYE2EYHdIp8qHjTKcJYPvO4PgaAH2pSruP55FOtNs5jWsgdeg7YK6OgJ0daSu21kN7aSzU19NRXRqC4bfITZYQ "
  );

在Firebase控制台中,密钥对旁边显示一个复制按钮.点击并粘贴...时,它将在密钥对的末尾添加一个随机空间.

In firebase console, theres a copy button that appears beside the key pair. When click on that and pasting....it adds a random space at the end of the key pair.

这篇关于Firebase Cloud Messaging:请求缺少必需的身份验证凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆