score:1
Accepted answer
here's what happens:
- webpage loads
- firebase starts a request to check whether the user is authenticated
- the app renders,
currentuser
is null - the authentication state changes, but the app doesn't re-render
the app needs to listen to changes in the authentication state and perform a re-render accordingly. https://firebase.google.com/docs/reference/js/firebase.auth.auth#onauthstatechanged
class app extends react.component {
state = {
currentuser: null
}
componentdidmount() {
this.unsubscribe = firebase.auth().onauthstatechanged(currentuser => {
this.setstate({ currentuser })
})
}
componentwillunmount() {
this.unsubscribe()
}
render() {
// use this.state.currentuser
}
}
Source: stackoverflow.com
Related Query
- Why Firebase user is not authenticated anymore when refreshing?
- React flashing Private Route when User is not authenticated
- Why is the registered user not Authenticated in Firebase? Why can't the user add products to the database Firebase?
- Why is video not displaying when user joins room?
- When the user logs in, logout button must show, but it's not showing instantly. Why is it happening?
- I have a icon within the button , I want that when user click that icon the button disapper in other words it shoulb not be visible anymore
- Why is the user not persisted on a page refresh with Firebase and Firebase React Hooks?
- Why is user data not storing into firebase firestore?
- redirect to login page when user is not authenticated
- When Ever i make user to signup through firebase he is authenticate but data is not written in firebase db?
- When user is not logged in redirect to login. Reactjs
- componentWillUnmount() not being called when refreshing the current page
- Why am I getting ReferenceError: self is not defined when I import a client-side library?
- Why does jest-dom give the error "TypeError: expect(...).not.toBeVisible is not a function" when I use it
- Why is componentDidMount not being called when I re-render?
- Recoil not persisting state, when refreshing page
- Why is my React checkbox onChange handler firing on render and then not when the box is clicked?
- 404 page not found when running firebase deploy
- Why do componentWillUpdate() and componentWillMount() not trigger render function when setState used in these methods?
- How to show Error or Validation messages only after form is submitted and not when user is typing in antd?
- Why is OnChange not working when used in Formik?
- Why is React component rerendering when props has not changed?
- Firebase Auth - User not logged in after Firebase sign up and redirect
- Firebase auth.currentUser is null when loading the page, user loaded when authstatechange called after some milli seconds of page load
- Why do I encounter: "TypeError: t(...).isPlaceholder is not a function" when "import './bootstrap/dist/css/bootstrap.min.css'"
- Why is TestUtils.Simulate.click in Jest not working when used directly on React Components?
- Why react calls function in subcomponents event when this subsomponents not rendered?
- why is mouseup event not firing when releasing outside div in this react code (using window.addEventListener)
- React components not updating when firebase updates
- Check if user is logged in or not using firebase in react
More Query from same tag
- How to disable YouTube context menu in react player (reactjs)?
- Uncaught (in promise)
- Clean way to implement messagebox pattern in react
- Save images in S3 from React SPA with express backend
- Webpack React - CSS Loader Issue
- With Firebase , using react hooks , objects are not valid as a React child , (If you meant) to render a collection of children, use an array instead
- Svg Lineargradient not working with ReactJs
- React: TypeError: .map is not a function
- Find, update an element and change its index in array of objects
- Why does my timer component behave strangely when passing a dependency to useEffect?
- react-router-dom v5 - Link works, but Redirect and history.push() do not
- How to change dynamically the render of icons inside a table based on a type of the data coming
- Cannot convert undefined or null to object : Next.js || React
- Make a component optionally controlled or uncontrolled
- Why Does My React App Keep Failing To Compile?
- Enzime test for react component (shallow)
- Objects from django are displayed as numbers/ids
- Paypal unsubscribe button gives CSP error
- Import CSS File to Styled Component
- Javascript chained destructuring
- Why this code is causing infinite loop to happen?
- Identify current/active child routes
- embed PHP in react js
- How to implement Auth Code Flow with Okta
- Changing React Theme Context on button click
- invalid KeyPath in immutable js when everything looks fine?
- Why doesn't React component doesn't render even though webpack doesn't throw any errors?
- componentWillReceiveProps render multiple times
- Rendering in React.js
- How do I get rid of buttons in parent component when dropdown menu is visible in CSS?