Comments (5)
the issue here appears to be the authState doesn't have a loading value. its probably no that difficult to add one in. did you want to work on a PR?
from react-firebase.
Yes I can work on it. But I don't get much free time so i'll be a slow a bit.
from react-firebase.
Just hit this issue and it's... not ideal. Seems like there is a semi official Google maintained React bindings lib here https://github.com/FirebaseExtended/reactfire which supports loading states but the docs are SO Google. Seems unfinished and hard to follow.
For now one way around it is to store the current user in local storage and simply redirect away from the login page if they exist there. Not the best solution, but better than rendering confusing UI in my opinion until this is resolved.
Edit: seems like @rakannimer is using https://github.com/csfrequency/react-firebase-hooks in his NextJs demo app which has a loading
state provided through the useAuthState
hook so it might be good to check that out as well
from react-firebase.
As a possible solution I created my own AuthProvider
component which passes loading
to children via render props
import { Component } from 'react';
import firebase from 'firebase/app';
import { func } from 'prop-types';
export class AuthProvider extends Component {
state = {
loading: firebase.auth().currentUser === null,
user: firebase.auth().currentUser,
};
componentDidMount() {
firebase
.auth()
.onAuthStateChanged(
user => user && this.setState({ user, loading: false })
);
}
render() {
const { loading, user } = this.state;
return this.props.children({ loading, user });
}
}
AuthProvider.propTypes = {
children: func,
};
That being said, I've migrated to using react-firebase-hooks
as it seems to be a little more active
from react-firebase.
Just found this and it lines up with my own observations - it's impossible to know if the user is logged in instantly without using local storage https://stackoverflow.com/a/51856627/12128359. The firebase.auth().currentUser
method is not instant, I guess it makes some sort of async call.
Probably an okay solution would be to wire in ways to store the user in local storage within a provider like this. That way you can easily mutate the value in local storage in the onAuthStateChanged
observer callback and have it be accurate.
from react-firebase.
Related Issues (20)
- Add Support for Storage HOT 1
- FirebaseDatabaseNode should use its callback when the data at its path gets deleted HOT 1
- No way to update a document within a collection
- Usage of GPLv3 License
- Allow npm and yarn support for testing.
- Not obvious what databaseURL in config should be HOT 5
- Missing information from quickstart
- Allow multiple where clauses.
- npm package shouldn't include demo files HOT 1
- Is this project maintained? HOT 1
- How do I enable persistance in firestore
- Potential Security Issue HOT 1
- Compatibility with firebase version 9 (modular)
- Docs link is down
- Demo link moves weather extension
- Domain for documentation is fake or expired HOT 1
- FirestoreCollection mutliple queries with AND
- `IfFirebaseUnAuthed` causes React: Unknown Prop Warning HOT 1
- Firebase Google Login HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-firebase.