is there a way to keep a user logged in I mean authentication should not lost even after refreshing the app?
1 thought on “How to keep a user logged in”
Comments are closed.
Posted in Uncategorized
How to keep a user logged in
is there a way to keep a user logged in I mean authentication should not lost even after refreshing the app?
Author: Fantashit
2 thoughts on “How to keep a user logged in”
-
Yeah this should work as default. You do however need to check for this yourself when the app boots. I do something like so in the “first step component” of my app (cut down a lot):
class App extends React.Component { constructor() { super(); this.state = { loading: true, authenticated: false, }; } componentDidMount() { firebase.auth().onAuthStateChanged((user) => { if (user) { this.setState({ loading: false, authenticated: true }); } else { this.setState({ loading: false, authenticated: false }); } }); } render() { if (this.state.loading) return null; // Render loading/splash screen etc if (!this.state.authenticated) { return <Login />; } return <Home />; } }
Comments are closed.
is there a way to keep a user logged in I mean authentication should not lost even after refreshing the app?
Author: Fantashit
1 thought on “How to keep a user logged in”
-
Yeah this should work as default. You do however need to check for this yourself when the app boots. I do something like so in the “first step component” of my app (cut down a lot):
class App extends React.Component { constructor() { super(); this.state = { loading: true, authenticated: false, }; } componentDidMount() { firebase.auth().onAuthStateChanged((user) => { if (user) { this.setState({ loading: false, authenticated: true }); } else { this.setState({ loading: false, authenticated: false }); } }); } render() { if (this.state.loading) return null; // Render loading/splash screen etc if (!this.state.authenticated) { return <Login />; } return <Home />; } }
Comments are closed.
Yeah this should work as default. You do however need to check for this yourself when the app boots. I do something like so in the “first step component” of my app (cut down a lot):