Skip to content

Provide a method to probe whether the UI has a pending link or email mismatch operations #34

@bojeil-google

Description

@bojeil-google

In a usual scenario, the developer adds an onAuthStateChanged observer to listen to user state changes, when the user is null, the developer initiates the sign in widget. When the user is not null, the developer displays their logged in UI.
That's where the problem occurs. In many cases, the widget may have a pending link operation or in the middle of an email mismatch rendering. In both cases the user is logged in and the onAuthStateChanged as typically implemented will interrupt the flow and prevent the widget from completing the sign in flow properly.

To fix we need to provide a synchronous api on ui, we could call it "isPending()" which returns true if the ui still needs to be rendered to finish a pending operation and false if the widget flow is complete.

var alreadyRendered = false;
firebase.auth().onAuthStateChanged(function(user) {
if (ui.isPending()) {
// There is still a pending operation such as linking or email mismatch.
// Render the widget to finish the flow.
if (!alreadyRendered) {
ui.start(...);
}
return;
}
// No pending operation.
if (user) {
alreadyRendered = false;
// Render signed in page.
goToLoggedInPage();
} else {
// Render sign in widget to start the sign in flow.
ui.start(...);
alreadyRendered = true;
}
});

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions