Request is missing required authention credential.Expected OAuth 2 access token cookie or other valid authentication credential.
Operating System
Ubuntu 22.04.4
Environment (if applicable)
Chrome Version 126.0.6478.182, react: 17.0.1
Firebase SDK Version
firebase: 9.9.4
Firebase SDK Product(s)
Auth
Project Tooling
React, Javascript.
Detailed Problem Description
I am trying to register FCM token for 200 users,But out of 200 users for some users its failing to register token with 401 error.This is the error i am getting { "error":{ "code":401, "message":"Request is missing required authention credential.Expected OAuth 2 access token cookie or other valid authentication credential. see https://developers.google.com/identity/sign-in/web/devconsole project.", "status": UNAUTHORISED } }
Steps and code to reproduce issue
const firebaseApp = initializeApp(firebaseConfig);
export const messaging = getMessaging(firebaseApp); let swRegistration;
const requestForToken = async (registerFCMToken) => {
try {
swRegistration = await navigator.serviceWorker.register(${process.env.PUBLIC_URL}/firebase-messaging-sw.js);
messaging.swRegistration = swRegistration;
const currentToken = await getToken(messaging, {
serviceWorkerRegistration: swRegistration,
vapidKey: 'BJAig9HybaAM035dc-e4TQp0Aa0B4TEWMSiBLy14qddxnNlxRNhaaVMXIlDTI11Q-Mil_O4He4GT6hCco2im4uU'
});
return currentToken;
} catch (err) { console.log('An error occurred while retrieving token. ', err); throw err; } };