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

145
Views
cómo almacenar el usuario actual usando redux y firebase

Mi problema es que no puedo almacenar el usuario actual cuando inicio sesión con google, anteriormente solo he usado reaccionar para almacenar el usuario actual cuando inicia sesión y establezco nulo cuando cierra la sesión. Entonces, lo que quiero es almacenar el usuario actual, este es mi código:

 class HomeHeaderW extends React.Component { authListener = null; componentDidMount() { const { setCurrentUser, currentUser } = this.props this.authListener = auth.onAuthStateChanged(async userAuth => { if (userAuth) { console.log(currentUser) const userRef = await handleUserProfile(userAuth); userRef.onSnapshot(snapshot => { setCurrentUser({ id: snapshot.id, ...snapshot.data() }); }) } setCurrentUser(userAuth) }) } render() { const { currentUser } = this.props return (... } HomeHeaderW.defaultProps = { currentUser: null }; const mapStateToProps = ({ user }) => ({ currentUser: user.currentUser }) export default connect(mapStateToProps, null)(HomeHeaderW)

usuario.tipos.js

 const userTypes = { SET_CURRENT_USER: 'SET_CURRENT_USER' }; export default userTypes

usuario.reductor.js

 import userTypes from "./user.types"; const INITIAL_STATE = { currentUser: null }; const userReducer = (state = INITIAL_STATE, action) => { switch (action.type) { case userTypes.SET_CURRENT_USER: return { ...state, currentUser: action.payload } default: return state; } }; export default userReducer

usuario.acciones.js

 import userTypes from "./user.types"; export const setCurrentUser = user => ({ type: userTypes.SET_CURRENT_USER, payload: user })

utils.js

 export const handleUserProfile = async({ userAuth, additionalData }) => { if (!userAuth) return; const { uid } = userAuth; const userRef = firestore.doc(`users/${uid}`); const snapshot = await userRef.get(); if (!snapshot.exists) { const { displayName, email } = userAuth; const timestamp = new Date(); const userRoles = ['user']; try { await userRef.set({ displayName, email, createdDate: timestamp, userRoles, ...additionalData }); } catch (err) { console.log(err); } } return userRef; };

Entonces, cuando verifico el usuario actual en la consola, veo null . También tengo otro problema en la consola: HomeHeaderW.js:28 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'onSnapshot')

about 4 years ago · Juan Pablo Isaza
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!