Skip to content
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

[Google sign-in Android KO] With more than 5 Google accounts configured on the device #66

Open
lopspower opened this issue Nov 2, 2024 · 3 comments

Comments

@lopspower
Copy link

After several weeks of using this library on my apps, several users report that the “Google Sign-in” action doesn't work (nothing happens when you click).
After a huge amount of investigation, what these users had in common was that they all had more than 5 Google accounts configured on their device. The problem is automatically corrected as soon as they delete a few accounts.
Is it possible to make the action work regardless of the number of accounts installed on the device?

@mirzemehdi
Copy link
Owner

@lopspower this issue should be fixed as I remember.

In this PR(#40), this is fixed by @bom-bakbang.

So basically what you need is to set filterByAuthorizedAccounts to true.

/**
     * @param filterByAuthorizedAccounts set to true so users can choose between available accounts to sign in.
     * setting to false list any accounts that have previously been used to sign in to your app.
     */
    public suspend fun signIn(filterByAuthorizedAccounts: Boolean): GoogleUser?

Attaching stackoverflow issue: https://stackoverflow.com/questions/78538579/new-google-credential-manager-is-throwing-a-transactiontoolargeexception

@mirzemehdi
Copy link
Owner

for now this field is not exposed in GoogleButtonUiContainer composable. But what you can do as a workaround is just copy its code from repo and copy paste as below:

@Composable
public fun GoogleButtonUiContainer(
    modifier: Modifier = Modifier,
    onGoogleSignInResult: (GoogleUser?) -> Unit,
    content: @Composable UiContainerScope.() -> Unit,
) {
    val googleAuthProvider = GoogleAuthProvider.get()
    val googleAuthUiProvider = googleAuthProvider.getUiProvider()
    val coroutineScope = rememberCoroutineScope()
    val updatedOnResultFunc by rememberUpdatedState(onGoogleSignInResult)

    val uiContainerScope = remember {
        object : UiContainerScope {
            override fun onClick() {
                println("GoogleUiButtonContainer is clicked")
                coroutineScope.launch {
                    //Pass true for filterByAuthorizedAccounts to avoid 5 Google Accounts issue
                    val googleUser = googleAuthUiProvider.signIn(filterByAuthorizedAccounts = true) 
                    updatedOnResultFunc(googleUser)
                }
            }
        }
    }
    Box(modifier = modifier) { uiContainerScope.content() }

}


@lopspower
Copy link
Author

I can't use this code in my project because the get function is internal.
Is it possible to add an attribute in a future update to simply do this?
Screenshot 7

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

No branches or pull requests

2 participants