Skip to content

Move Auth notification constant into Core. #155

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 2 commits into from
Aug 4, 2017
Merged

Conversation

ryanwilson
Copy link
Member

SDKs that want to listen for the internal Auth notifications needed
to copy the notification strings to their own SDK instead of relying
on Auth's definition in order to avoid a dependency on Auth. By moving
them to Core, SDKs can use the constants without taking on another
dependency.

Copy link
Member Author

@ryanwilson ryanwilson left a comment

Choose a reason for hiding this comment

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

FIRDatabaseConfig.m already imports FIRApp.h, so I included it in FIRDatabase.m as well (FIRAppInternal) and removed some of the protocols mimicking the FIRApp and FIROptions interface.

Copy link
Contributor

@mikelehen mikelehen left a comment

Choose a reason for hiding this comment

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

This PR looks awesome. There are a couple additional things that I'd like to see (to make it possible for SDK components to consume these FIRApp APIs without the hackery database does), but we can tackle that separately if you don't want to add to this PR. This is already a great improvement.

* are invoked by name we can write code against this protocol as long as the method signatures don't change.
*
* TODO: Consider weak-linking the actual Firebase/Core framework or something.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for cleaning all this up!!!


@end


/**
* This is a hack that defines all the methods we need from FIRAuth.
*/
@protocol FIRFirebaseAuthLike <NSObject>
Copy link
Contributor

Choose a reason for hiding this comment

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

Erg... I forgot about this. It's another hack that will need to be copied anywhere else somebody tries to consume this notification. Maybe we should add a FIRAuthStateDidChangeInternalNotificationAppKey that contains the FIRApp instance in the notification object?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea! I'll add it.


@end

/**
* This is a hack that copies the definitions of Firebase Auth error codes. If the error codes change in the original code, this
* will break at runtime due to undefined behavior!
*/
typedef NS_ENUM(NSUInteger, FIRErrorCode) {
/*! @var FIRErrorCodeNoAuth
typedef NS_ENUM(NSUInteger, FIRMockErrorCode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hrm. This is another FIRApp hack that we should ideally remove. The consumer can't tell if [FIRApp getTokenForcingRefresh:] actually tried to get a token and failed (e.g. no network connection so we can't talk to the backend) or if the app just doesn't use auth (so we should proceed unauthenticated), or because the app uses auth but no user is currently signed in (so again we should proceed unauthenticated).

Any chance we can tackle this too (move these errors into core perhaps) here or in a subsequent PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll take a look - I wasn't actually sure what this mapped to. There was already FIRErrorCode declared but doesn't seem to match up with the values here. Do you know where these were copied from?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, interesting! I'm pretty sure these were errors copied from FIRAuth, but I can't find them either... and looking at the implementation of [FIRApp getTokenForcingRefresh] and the getTokenImplementation that auth provides, I believe our callback will just be called with a nil token if auth is not configured or there is no user signed in... which is exactly what database wants anyway.

So my best guess is that this is some legacy error handling that's no longer needed. We should ideally rip it out, but if we're nervous, we could just add a big comment that this is probably legacy and should be removed.

Copy link
Contributor

@XiangtianDai XiangtianDai Jul 27, 2017

Choose a reason for hiding this comment

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

Yes, this is legacy code. FIRAuth used to callback with error codes FIRAppErrorCodeNoAuth and FIRAppErrorCodeNoSignedInUser, but as part of the transition from FIRFirebaseApp to FIRApp before we launched publicly last year, both error codes are removed in these cases, and a nil error is returned instead along with a nil user. See b/27696080 for code history. I see no harm removing the legacy code, but it's really up to you two.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, looking at the other implementations, it looks alright to just forward the token and error to the local callback via callback(token, error);, or would you prefer I wrap it in case it changes in the future? Ex:

if (error != nil) {
  callback(nil, error);
} else {
  callback(token, nil);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome, thanks @XiangtianDai for digging up the history and confirming. @ryanwilson I think it's fine to just forward directly.

@paulb777
Copy link
Member

Does this PR address #160?

@ryanwilson
Copy link
Member Author

@paulb777 I'll look into it and see if I can address it as well.

@mikelehen
Copy link
Contributor

FYI- This PR looks good to me. Thanks for the additional changes, Ryan.

I think #160 is probably mostly unrelated (I guess database needs to listen for the delete notification and clean itself up?).

@ryanwilson
Copy link
Member Author

Had to solve a merge conflict - will be testing this tomorrow and if all goes well, submitting it tomorrow as well.

@paulb777
Copy link
Member

paulb777 commented Aug 3, 2017

This PR's diff looks corrupted. It should not show all the diffs from the merges - it should only show the diff of the PR to master. Probably need to rebase to latest master, verify the diff, and force push. Let's discuss.

SDKs that want to listen for the internal Auth notifications needed
to copy the notification strings to their own SDK instead of relying
on Auth's definition in order to avoid a dependency on Auth. By moving
them to Core, SDKs can use the constants without taking on another
dependency.
@ryanwilson ryanwilson force-pushed the rw-auth-listener-core branch from fad3e03 to 0d70209 Compare August 4, 2017 17:19
@ryanwilson
Copy link
Member Author

Thanks Paul, fixed the issue.

Re: #160 I'll address that in a different PR.

@ryanwilson
Copy link
Member Author

Tested with test project and build CocoaPod, should be good to go! Will land it.

@ryanwilson ryanwilson merged commit 6e00706 into master Aug 4, 2017
@ryanwilson ryanwilson deleted the rw-auth-listener-core branch August 4, 2017 22:42
@mikelehen
Copy link
Contributor

Thanks again for getting this all cleaned up! 👍

minafarid pushed a commit to minafarid/firebase-ios-sdk that referenced this pull request Jun 6, 2018
* Move Auth notification constant into Core.

SDKs that want to listen for the internal Auth notifications needed
to copy the notification strings to their own SDK instead of relying
on Auth's definition in order to avoid a dependency on Auth. By moving
them to Core, SDKs can use the constants without taking on another
dependency.

* Remove Auth stub, add app instance to notification.
@firebase firebase locked and limited conversation to collaborators Nov 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants