Skip to content

Cleanup + make sure IdpResponse is never null if resultCode == ResultCodes.OK #469

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

Merged
merged 10 commits into from
Dec 22, 2016
Merged

Conversation

SUPERCILEX
Copy link
Collaborator

#468

Note: this PR includes #447 to make my life easier. 😄

@SUPERCILEX SUPERCILEX changed the base branch from master to version-1.1.0-dev December 22, 2016 01:44
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
@samtstern
Copy link
Contributor

@SUPERCILEX I went ahead and merged #447 (commented there on reasoning) so you should be able to make the diff for this sane now.

@branflake2267
Copy link

nice job!

…ponse

# Conflicts:
#	auth/src/main/java/com/firebase/ui/auth/ui/ExtraConstants.java
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
@@ -17,4 +13,8 @@ private ErrorCodes() {
* An unknown error has occurred
**/
public static final int UNKNOWN_ERROR = 20;

private ErrorCodes() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why do we need a constructor for this class at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't, this was just formalizing the class as a "Constants" class that shouldn't be instantiated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Had not seen that technique before but I like it.

ExtraConstants.EXTRA_ERROR_MESSAGE,
"Firebase login successful." +
" Account linking failed due to provider not enabled by application");
Log.w(TAG, "Firebase login successful." +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this error message should include which provider was not enabled.

TAG, "Error signing in with previous credential"))
.addOnCompleteListener(new FinishListener(idpResponse));
} else {
finish(ResultCodes.OK, IdpResponse.getIntent(idpResponse));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This finish() was previously for failure of the Task but not it occurs when the task succeeds but mPrevCredential == null. Is this a behavior change for developers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was the original intention: if we have a previous credential, link it, else, finish ok. Previously, if we either didn't have a previous credential or the task failed, we would finish ok.

Because we would finish ok if we didn't have a previous credential, this isn't a behavior change.

Signed-off-by: Alex Saveau <[email protected]>
token = mIdpResponse.getIdpToken();
secret = mIdpResponse.getIdpSecret();
}
if (token == null) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only show the token/secret if we have one.


<CheckBox
android:id="@+id/facebook_provider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make all providers be checked by default and use standard order: Google, Facebook, Twitter, Email.

import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GoogleAuthProvider;
import com.google.firebase.auth.TwitterAuthProvider;

public class WelcomeBackIdpPrompt extends AppCompatBase
implements View.OnClickListener, IdpCallback {
public class WelcomeBackIdpPrompt extends AppCompatBase implements IdpCallback {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was a mess!!! I've been struggling to understand what's going on in #309 for a while now so I decided it was time for a rewrite. If you look at the class without all the crazy diff stuff, it's much clearer what's going on now.

@@ -127,83 +123,71 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}

@Override
public void onClick(View view) {
next(mPrevIdpResponse);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhhhhh!!! It took me so long in #309 to "understand" what was going on only to find out I was wrong: we never even used this click listener! That kills me!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it took me a little while to see what was going on here too. Good find! This stray listener could have bitten us down the road.

if (task.isSuccessful() && mPrevCredential != null) {
FirebaseUser firebaseUser = task.getResult().getUser();
firebaseUser.linkWithCredential(mPrevCredential);
firebaseAuth.signOut();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😢

TAG, "Error signing in with previous credential"))
.addOnCompleteListener(new FinishListener(newIdpResponse));
} else {
finish(ResultCodes.OK, IdpResponse.getIntent(newIdpResponse));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BAD! (I think)
Here's the if: if (task.isSuccessful() && mPrevCredential != null)
What if the task fails!? We'll just finish with result ok? I'm pretty sure this was a mistake.

.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
finishWithError();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On failure, we fail.

mActivityHelper.getFlowParams(),
mEmail));
finish(ResultCodes.OK, new Intent());
finish(ResultCodes.CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was also a mistake, the user is not signed in so we shouldn't finish with OK.

@@ -94,12 +95,6 @@ public void onFailure(@NonNull Exception e) {
}

private class StartWelcomeBackFlow implements OnSuccessListener<ProviderQueryResult> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class isn't static so I'm not sure why we passed in the email. Seems like extra boilerplate to me.

if (!mHelper.getFlowParams().smartLockEnabled
|| !PlayServicesHelper.getInstance(getContext()).isPlayServicesAvailable()
|| getActivity().isFinishing()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was pre setRetainInstance(true), my bad.

Signed-off-by: Alex Saveau <[email protected]>
@samtstern
Copy link
Contributor

This LGTM! Gonna squash and merge.

@samtstern samtstern merged commit 81dbbca into firebase:version-1.1.0-dev Dec 22, 2016
@SUPERCILEX SUPERCILEX deleted the IdpResponse branch December 22, 2016 22:29
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

Successfully merging this pull request may close these issues.

3 participants