-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Cleanup + make sure IdpResponse is never null if resultCode == ResultCodes.OK #469
Conversation
Signed-off-by: Alex Saveau <[email protected]>
…ull if resultCode == ResultCodes.OK Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
@SUPERCILEX I went ahead and merged #447 (commented there on reasoning) so you should be able to make the diff for this sane now. |
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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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." + |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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]>
This LGTM! Gonna squash and merge. |
#468
Note: this PR includes #447 to make my life easier. 😄