Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
How to set useState by checking User data in Firebase

I can't seem to figure out how to set useState after querying Firebase. I need BOX to be equal to "public URL" for everyone except for admin.

import { auth } from "../firebase";
...
  const [BOX, setBox] = useState('');
  useEffect(() => {
if (auth.currentUser?.email === "admin@yahoo.com") {
  setBox("https://admin/link");
   } else {
     setBox("https://public/link");
   }
 },[auth]);

Errors are always different. Sometimes it returns "...empty link", sometimes "network request failed". Sometimes it does show the correct data, but it runs into one of the errors when I refresh the screen.

Here is my firebase file

// Import the functions you need from the SDKs you need
import * as firebase from "firebase";
import 'firebase/firestore';
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
const firebaseConfig = {
...
};

// Initialize Firebase

let app;
if (firebase.apps.length === 0) {
    app = firebase.initializeApp(firebaseConfig);
} else {
    app = firebase.app()
}

const auth = firebase.auth();
const dbFirebase = app.firestore();

export {auth, dbFirebase};
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can not use hook inside an if statement...

 const [box, setBox] = useState('');
  
useEffect(() => {
    if (auth.currentUser?.email === "admin@yahoo.com") {
      setBox("https://admin/link");
       } else {
         setBox("https://public/link");
       }
 },[auth]);
  
about 4 years ago · Juan Pablo Isaza Report

0

For firebase 9 you will need to configure it like below:

import { initializeApp } from 'firebase/app'
import { getAuth } from 'firebase/auth'

const firebaseConfig = {...}

initializeApp(firebaseConfig)

export const auth = getAuth()
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!