Skip to content

Commit

Permalink
Adding filterByAuthorizedAccounts to signIn function for Google (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirzemehdi authored Oct 5, 2024
1 parent d942b84 commit 0f21c3f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ internal class GoogleAuthUiProviderImpl(
private val googleLegacyAuthentication: GoogleLegacyAuthentication,
) :
GoogleAuthUiProvider {
override suspend fun signIn(): GoogleUser? {
override suspend fun signIn(filterByAuthorizedAccounts: Boolean): GoogleUser? {
return try {
getGoogleUserFromCredential(filterByAuthorizedAccounts = true)
getGoogleUserFromCredential(filterByAuthorizedAccounts = filterByAuthorizedAccounts)
} catch (e: NoCredentialException) {
if (!filterByAuthorizedAccounts) return handleCredentialException(e)
try {
getGoogleUserFromCredential(filterByAuthorizedAccounts = false)
} catch (e: GetCredentialException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal class GoogleLegacyAuthentication(

) : GoogleAuthUiProvider {

override suspend fun signIn(): GoogleUser? {
override suspend fun signIn(filterByAuthorizedAccounts: Boolean): GoogleUser? {
val signInClient = getGoogleSignInClient().signInIntent
activityResultState.isInProgress = true
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ public interface GoogleAuthUiProvider {
/**
* Opens Sign In with Google UI, and returns [GoogleUser]
* if sign-in was successful, otherwise, null
* By default all available accounts are listed to choose from
* @see signIn(filterByAuthorizedAccounts: Boolean)
* @return returns GoogleUser or null(if sign-in was not successful)
*/
public suspend fun signIn(): GoogleUser?
public suspend fun signIn(): GoogleUser? = signIn(filterByAuthorizedAccounts = false)

/**
* @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?
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlin.coroutines.suspendCoroutine

internal class GoogleAuthUiProviderImpl : GoogleAuthUiProvider {
@OptIn(ExperimentalForeignApi::class)
override suspend fun signIn(): GoogleUser? = suspendCoroutine { continutation ->
override suspend fun signIn(filterByAuthorizedAccounts: Boolean): GoogleUser? = suspendCoroutine { continutation ->

val rootViewController =
UIApplication.sharedApplication.keyWindow?.rootViewController
Expand Down

0 comments on commit 0f21c3f

Please sign in to comment.