Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I have Persistent state #8

Closed
saostad opened this issue Dec 1, 2017 · 7 comments
Closed

How can I have Persistent state #8

saostad opened this issue Dec 1, 2017 · 7 comments

Comments

@saostad
Copy link

saostad commented Dec 1, 2017

How can I have Persistent State?
Now I have to do authenticate after every page refresh.

I tried to use firebase docs but it doesn't work for me.

https://firebase.google.com/docs/auth/web/auth-state-persistence?authuser=0

@bojeil-google
Copy link
Contributor

Please provide more information on your environment.

@saostad
Copy link
Author

saostad commented Dec 1, 2017

this is how I use the component:

import firebase from 'firebase/app';
import firebaseApp from './services/firebase.config';
import { FirebaseAuth } from 'react-firebaseui';

And in component class:

uiConfig = {
    signInFlow: 'popup',
    signInOptions: [
      firebase.auth.GoogleAuthProvider.PROVIDER_ID,
      firebase.auth.FacebookAuthProvider.PROVIDER_ID,
      firebase.auth.EmailAuthProvider.PROVIDER_ID,
    ],
    callbacks: {
      signInSuccess: () => {
        const user = firebase.auth().currentUser;        
        this.props.actions.userLogIn(user);
        this.props.actions.loadCategories(user.uid);
        return false;
      }
    }
  };
return (
{!this.props.user.signedIn &&
          <div>
            <FirebaseAuth uiConfig={this.uiConfig} 
              firebaseAuth={firebaseApp.auth()}
              />
          </div>
        }
        {this.props.user.signedIn &&
          <p>You Signed In! </p>
        }
);

@bojeil-google
Copy link
Contributor

Do you even check onAuthStateChanged ? FirebaseUI will render whenever it is called even if a user is logged in.

@saostad
Copy link
Author

saostad commented Dec 1, 2017

actually I am using redux to check the status of logged in user, and in every successful login I do update the state.
is there any place to look in initial state management to see if user logged in in the past?

@bojeil-google
Copy link
Contributor

Please read the documentation on how to determine the state of a user: https://firebase.google.com/docs/auth/web/manage-users

@saostad
Copy link
Author

saostad commented Dec 1, 2017

Thanks,
this is how it works for me:

componentWillMount(){
    const that = this;
    firebaseApp.auth().onAuthStateChanged(function(user) {
      if (user) {
        that.doSignIn();
      }
    });    
  }

@rwieruch
Copy link

For anyone who stumbles upon this, maybe this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants