react-native-google-signin / google-signin

Google Sign-in for your React Native applications
https://react-native-google-signin.github.io/
MIT License
3.19k stars 877 forks source link

Support multiple accounts simultaneously #200

Open derabbink opened 7 years ago

derabbink commented 7 years ago

This is a feature request. Since GoogleSignin is exported as a singleton, developers cannot create separate - differently configured - instances for use in an app that is signed into multiple accounts simultaneously.

This is relevant for using Google APIs on behalf of multiple Google accounts simultaneously, where the APIs operate on resources that cannot be shared between Google accounts. Examples of such APIs are those that are part of GSuite/Google Apps for Business APIs, and which are only available to domain admins.

xuezhma commented 7 years ago

+1

AndreiCalazans commented 6 years ago

This is indeed very interesting feature. Please feel free to send PR to contribute.

vonovak commented 6 years ago

~I believe we will get to this soon.~ I don't have time and need for this, contributions are welcome (please open an issue to discuss first).

casey-budee commented 5 years ago

Has there been any progress with this feature?

AndreiCalazans commented 5 years ago

No one has submitted any PRs for it @casey-budee 😢

mikehardy commented 4 years ago

Hey amazing react-native-google-signin people (and I mean that, I'm using this library, I followed the instructions and it worked, that's amazing)

Anyone have a sketch of what would be required here? Or some example code (maybe other language from flutter or pure android or whatever) where they handle it?

I'm not asking anyone to do a bunch of work here, just if anyone that has familiarity with the code and thought through it before wants to brain dump, it might be the baton I or someone else could pick up to then propose a PR

Cheers

vonovak commented 4 years ago

hi @mikehardy thanks for the kind words.

As for how to handle multiple users - the JS apis mirror the native apis, meaning the native apis also do not give a strong hint that multiple users are supported (eg. there is no users array in the native apis, there is just currentUser). So the next possibility is to look at the native classes that provide sign in functionality, maybe we can have multiple instances of those and switch between them?

On android this is done via GoogleSignInClient here and is should be possible to have multiple instances of that class. But on iOS, there is the [GIDSignIn sharedInstance] call here and to me that sounds like a singleton so there is (afaik?) no way to create multiple instances of anything here. So, to sum up, without extra research I'm not sure how to do this right.

One possible way to support multiple users (which may not work for everybody though) would be to call signOut before you call signIn for the next user, so for user it'd look as if multiple users were supported where in fact only one would be handled at a time. If the second one cancels the sign in process though, that might be an issue as no user will be logged in at that point.

To respond to the first post, It's true the exported JS class is a singleton, but that is not the limiting factor here.

some resources:

SO - ios - it may be possible to rewrite this library to use GTMAppAuth SO - android