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

signOut() does not restore the login ui #559

Closed
jimmont opened this issue Feb 18, 2019 · 2 comments
Closed

signOut() does not restore the login ui #559

jimmont opened this issue Feb 18, 2019 · 2 comments

Comments

@jimmont
Copy link

jimmont commented Feb 18, 2019

  • Operating System version: macos 10.13
  • Browser version: chrome 72.0.3626.109
  • Firebase UI version: firebaseui/3.5.2
  • Firebase SDK version: firebase/5.8.3

problem:
logout action (from ui button) firebase.auth().signOut() does not restore the firebaseui; meaning there is no prompt to login again or the ui expected initially (as before logging in)--it does not return to the initial state.

scenario: single-page app, use the provided web-ui to login successfully, later click a logout button to logout at that browser/client;

related: if I hard-reload the prompt to login exists and my own state management shows it again after logout, providing the desired effect.

			new firebaseui.auth.AuthUI(auth)
			.start('#authui', {
				callbacks: {
					signInSuccessWithAuthResult:  function(res, redirectUrl){
						return false;
					}
					,signInFailure: function(error){
// omitted
					}
				}
				,signInOptions: [
				{ provider: firebase.auth.GoogleAuthProvider.PROVIDER_ID
					,customParameters:{prompt:'select_account'}
					,scopes: ['email','profile']
					,authMethod: 'https://accounts.google.com'
					},
					{ provider: firebase.auth.EmailAuthProvider.PROVIDER_ID, requireDisplayName: true }
				],
				tosUrl: '/terms.html',
				privacyPolicyUrl: '/privacy.html'
			});
		})


@bojeil-google
Copy link
Contributor

The UI does not re-render itself on sign out.
One common way to render the UI when needed in a single page app is as follows:

var ui = new firebaseui.auth.AuthUI(auth);
firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    // Show user signed in screen. Reset if user just signed in. (Single page app)
    ui.reset();
  } else {
    // No user signed in, render sign-in UI.
    ui.start(config);
  }
});

When the user signs out, the listener will trigger with no user and render the UI.
Note I have not tested the code above but it should work in theory.

@jimmont
Copy link
Author

jimmont commented Feb 19, 2019

thanks @bojeil-google this doesn't work (in my scenario at least) and it led me to what does work which is to add the ui re-start in the logout handling below. If there's a more appropriate way to do this please add a link or comment--and thanks for it.

	logout(){
		// returns nothing (no response)
		return firebase.auth().signOut().then((res)=>{
console.log('signOut ok',res);
			ui.start('#auth-web-ui', uiConfig);
			return res || 'okay';
		}).catch((err)=>{
console.warn('signOut error',res);
			return err || 'error';
		})
		.finally((res)=>{
console.log('signOut resolved', res);
			// stateChange handles all of my instances onAuthStateChanged and application state
			this.stateChange();
		});
	}

@jimmont jimmont closed this as completed Feb 28, 2019
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

2 participants