Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

321
Visualizações
Firebase auth not working on before mount hook and I don't know why

I'm using firebase for the first time and stuck on this error that I can't fix.

Basically I have a home screen and a login screen. When I run onBeforeMount to check if a user is logged in or not I'm getting the following errors:

Uncaught ReferenceError: onAuthStateChanged is not defined
at eval (webpack-internal:///./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/App.vue?vue&type=script&lang=js:12:7)
at callWithErrorHandling (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:357:18)
at callWithAsyncErrorHandling (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:367:17)
at Array.hook.__weh.hook.__weh (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:3388:19)
at invokeArrayFns (webpack-internal:///./node_modules/@vue/shared/dist/shared.esm-bundler.js:648:11)
at ReactiveEffect.componentUpdateFn [as fn] (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:6089:70)
at ReactiveEffect.run (webpack-internal:///./node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js:237:19)
at setupRenderEffect (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:6294:5)
at mountComponent (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:6029:5)
at processComponent (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:5979:9)

Here is what is in my main.js file:

import { createApp } from 'vue'
import App from './App.vue'
import './registerServiceWorker'
import router from './router'
import { initializeApp } from "firebase/app";

const firebaseConfig = {
  apiKey: "Censored",
  authDomain: "Censored",
  projectId: "Censored",
  storageBucket: "Censored",
  messagingSenderId: "Censored",
  appId: "Censored"
};

const app = initializeApp(firebaseConfig);

createApp(App).use(router).mount('#app')

And here is the script in my app.vue file

<script>
import { onBeforeMount } from "vue";
import router from "@/router";
import { getAuth } from "firebase/auth";

export default {
  setup() {
    onBeforeMount(() => {
      const auth = getAuth();

      onAuthStateChanged(auth, (user) => {
        if (!user) {
          router.replace("/login");
        } else if (route.path == "/login" || route.path == "/signup") {
          router.replace("/");
        }
      });
    });
  },
};
</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

onAuthStateChanged need to be imported to

import { getAuth, onAuthStateChanged } from "firebase/auth"

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda