adventures-in / chat_app

A group effort to build a chat app and learn as we go.
18 stars 0 forks source link

Implement facebook sign in #19

Closed nickmeinhold closed 4 years ago

gaslitbytech commented 4 years ago

Latest commit screenshot of error

Given URL is not allowed by the application configuration. One or more of the given URLs is not allowed by the App's settings. To use this URL you must add a valid native platform in your App's settings.

image

Likely solution:

https://stackoverflow.com/questions/31883079/ios-facebook-login-given-url-is-not-allowed-by-the-application-configuration

@nickmeinhold is it okay to create a new Bundle Id through https://developer.apple.com/documentation/appstoreconnectapi/bundle_ids ? Is that the right thing to do?

Nevermind found it in xcode.

nickmeinhold commented 4 years ago

@tourdownunder are you working on this? I think the solution is probably adding the redirect url as per https://stackoverflow.com/a/21237276/1992736

Shall I do that? Just didn't want to mess around if you're in the middle of doing the same thing...

nickmeinhold commented 4 years ago

Sorry, I think I'm on the wrong track with that last post, please ignore me for now while I look into it further.

gaslitbytech commented 4 years ago

I got a little further

Exception has occurred. PlatformException (PlatformException(ERROR_OPERATION_NOT_ALLOWED, The identity provider configuration is not found., null))

Screen Shot 2020-02-15 at 8 46 24 pm

I'll commit to branch shortly

nickmeinhold commented 4 years ago

Awesome! I got your branch and it seems to work at my end, I'm on commit with commit message "issue #19 a bit futher."

When I say it works, the facebook sign in flow goes right through and then an alert dialog is displayed

EDIT: and I only tested iOS

gaslitbytech commented 4 years ago

I also only tested iOS and on same git commit.

Yes its this alert dialog shouldn't be displayed as the workflow is the same as the google auth. image

Issue seems to be with the line

wait _fireAuth.signInWithCredential(credential);

My current guess is that we need to update the firebase to allow Facebook auth.

From firebase docs

Enable Facebook Login: In the Firebase console, open the Auth section. On the Sign in method tab, enable the Facebook sign-in method and specify the App ID and App Secret you got from Facebook. Then, make sure your OAuth redirect URI (e.g. my-app-12345.firebaseapp.com/__/auth/handler) is listed as one of your OAuth redirect URIs in your Facebook app's settings page on the Facebook for Developers site in the Product Settings > Facebook Login config.

nickmeinhold commented 4 years ago

Ah yes of course!

I've enabled Facebook sign in in Firebase and I added you to the Firebase project so in future you don't have get held up waiting.

I'll test again...

nickmeinhold commented 4 years ago

Cool, I think it's working - I still get an error but the error message is "An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated wit…"

Bit of a tangent but how did you think we should deal with this error? A nice UX I think is to check for the error specifically and offer an option to link the accounts. There's a config option I think to not throw an error in this situation and just create a new account. Personally I think that's a bad option.

Just displaying the error seems like probably enough at this point?

nickmeinhold commented 4 years ago

The "Adventures In Chat App" facebook app I created seems to have been replaced by an old one of mine called Good Food. I don't know what's going on but I'll get to the bottom of it and change any config stuff so we're using the Adventures In Chat App facebook app.

gaslitbytech commented 4 years ago

Bit of a tangent but how did you think we should deal with this error? A nice UX I think is to check for the error specifically and offer an option to link the accounts. There's a config option I think to not throw an error in this situation and just create a new account. Personally I think that's a bad option.

I think if we can pull off allowing a user to use whatever signin they like it would be best. Seems possible

https://support.google.com/firebase/answer/9134820?hl=en&ref_topic=6386702

nickmeinhold commented 4 years ago

Yeah it's very doable man, I have set it up in a project at some point in the past and it's probably sitting somewhere in my github if you think it would be helpful.

It's slightly more complex than it might seem at first glance - we need to check for the specific error then prompt the user to sign in with the auth provider they used previously, then start the sign in sequence with the callback set to link the accounts when it completes. And we'll need some extra state management stuff so we have the credentials available for the call to link the accounts. And we need some extra UI of course as it's a separate sign in flow so we either modify the existing UI to have 2 modes or make a separate UI for the second sign in and linking.

Anyway I think it would be fun and not too difficult. I agree that having the option to link accounts is the best experience. I was really just wondering whether we should do it now or later. Also whether we do it at sign in or just provide the error message and have a Link Accounts page in the app (we probably want to have that page anyway). Personally I don't have a strong opinion either way.

For the Flutter firebase_auth package the option to link accounts is in the FirebaseUser class

nickmeinhold commented 4 years ago

I've pulled the linking accounts feature out into a separate issue #27