Код: Выделить всё
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import { BrowserRouter } from 'react-router-dom';
import { initializeApp } from 'firebase/app';
import { getFirestore } from 'firebase/firestore';
import { getAuth } from 'firebase/auth';
//firebase config stores the data for the database and application. It was removed for security reasons
const app = initializeApp(firebase_conf)
const db = getFirestore(app)
const auth = getAuth(app)
export { db, auth };
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
);
Код: Выделить всё
// Initialize Firebase app
const app = initializeApp(firebaseConfig);
// Initialize Firestore and Auth
const db = getFirestore(app);
const auth = getAuth(app);
// Set up authentication state observer
function setupAuthObserver() {
onAuthStateChanged(auth, async (user) => {
if (user) {
// Check if email is verified and update Firestore if it has changed
if (user.emailVerified) {
const userDocRef = doc(db, 'users', user.uid);
try {
// Get current user data from Firestore
const userDoc = await getDoc(userDocRef);
// Check if the document exists and email verification status needs updating
if (userDoc.exists() && userDoc.data().emailVerified === false) {
console.log('Updating email verification status in Firestore');
// Update the email verification status
await setDoc(userDocRef, {
emailVerified: true
}, { merge: true });
console.log('Email verification status updated successfully');
}
} catch (error) {
console.error('Error updating email verification status:', error);
}
}
modifyNavBar();
}
});
}
// Initialize the observer when the module loads
setupAuthObserver();
// Nav logic that always uses absolute links:
function modifyNavBar() {
let anchors = document.querySelector('header').querySelectorAll('a');
let loglinks = ['#', `http://localhost:3000/peerscribe/webapp/dashboard`];
let dynamicAnchors = [anchors[3], anchors[4]];// WILL NEED TO BE CHANGED IF MORE NAVLINKS ARE ADDED
let text = ["logout", "webapp"];
for (let i = 0;i
Вещи, которые я пробовал: < /p>
Использование idtokens от Firebase (не пользовательские токены) < /li>
Использование cookie < /li>
Пропустить объект аутентификации Firebase Autentication It Emploarive Imer It Emploarive Imer. Желаемый пользователь из ссылки на Firebase Firestore (который был инициализирован), он возвращает пользовательский идентификатор. Я знаю, что пользователь и документ существует в первой коллекции. Я также знаю, что он видит и извлекает все документы в рамках сбора вместе с каждыми документами соответствующих данных. Однако при попытке использовать в настоящее время аутентифицированный UserId (auth.currentUser
Подробнее здесь: https://stackoverflow.com/questions/794 ... t-ports-si