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

178
Views
Cómo exportar var asíncrono desde un inicio de sesión

Estoy tratando de exportar información de usuario desde el inicio de sesión a otros módulos.

 export function login(){ console.log("entrando A LOGIN") var provider = new firebase.auth.GoogleAuthProvider(); firebase.auth() .signInWithPopup(provider) .then((result) => { /** @type {firebase.auth.OAuthCredential} */ var credential = result.credential; var token = credential.accessToken; // The signed-in user info. let user = result.user; module.exports.user=user /// it says it does not provide user variable when in this ine I am doing it

}etc....

/// dice que no proporciona variable de usuario pero lo hago. Gracias soy nuevo

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No necesita usar module.exports en absoluto, que yo sepa. Y realmente no quieres mezclarlos con módulos es6.

 // google-auth.js export function login() { const provider = new firebase.auth.GoogleAuthProvider(); return firebase.auth() .signInWithPopup(provider) .then((result) => { const credential = result.credential; const token = credential.accessToken; const user = result.user; return user; }) .catch(error => { // you deal with errors that happen here }) }

Obtiene el objeto de usuario devolviéndolo desde la función. Sin embargo, la función devuelve una promesa, por lo que si intenta hacer algo como const user = login() no funcionará . Para importar la función a otro archivo y usarla de manera que pueda acceder al objeto de usuario, debería haz algo como esto:

 // login.js import { login } from './path/to/google-auth.js' const authInstance = login();

De los documentos oficiales:

 import { getAuth, signInWithPopup, GoogleAuthProvider } from "firebase/auth"; const auth = getAuth(); signInWithPopup(auth, provider) .then((result) => { // This gives you a Google Access Token. You can use it to access the Google API. const credential = GoogleAuthProvider.credentialFromResult(result); const token = credential.accessToken; // The signed-in user info. const user = result.user; // ... }).catch((error) => { // Handle Errors here. const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. const email = error.email; // The AuthCredential type that was used. const credential = GoogleAuthProvider.credentialFromError(error); // ... });
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!