@capgo/capacitor-social-login 0.0.34 → 0.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,6 +18,7 @@ import androidx.credentials.exceptions.NoCredentialException;
18
18
  import com.getcapacitor.JSObject;
19
19
  import com.getcapacitor.PluginCall;
20
20
  import com.google.android.libraries.identity.googleid.GetGoogleIdOption;
21
+ import com.google.android.libraries.identity.googleid.GetSignInWithGoogleOption;
21
22
  import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential;
22
23
  import ee.forgr.capacitor.social.login.helpers.SocialProvider;
23
24
  import java.util.concurrent.Executor;
@@ -54,17 +55,18 @@ public class GoogleProvider implements SocialProvider {
54
55
  String nonce = call.getString("nonce");
55
56
 
56
57
  // First attempt with setFilterByAuthorizedAccounts(true)
57
- GetGoogleIdOption.Builder googleIdOptionBuilder =
58
- new GetGoogleIdOption.Builder()
59
- .setFilterByAuthorizedAccounts(true)
60
- .setServerClientId(this.clientId)
61
- .setAutoSelectEnabled(true);
58
+ // GetGoogleIdOption.Builder googleIdOptionBuilder =
59
+ // new GetGoogleIdOption.Builder()
60
+ // .setFilterByAuthorizedAccounts(true)
61
+ // .setServerClientId(this.clientId)
62
+ // .setAutoSelectEnabled(true);
63
+ GetSignInWithGoogleOption.Builder googleIdOptionBuilder = new GetSignInWithGoogleOption.Builder(this.clientId);
62
64
 
63
65
  if (nonce != null && !nonce.isEmpty()) {
64
66
  googleIdOptionBuilder.setNonce(nonce);
65
67
  }
66
68
 
67
- GetGoogleIdOption googleIdOptionFiltered = googleIdOptionBuilder.build();
69
+ GetSignInWithGoogleOption googleIdOptionFiltered = googleIdOptionBuilder.build();
68
70
  GetCredentialRequest filteredRequest = new GetCredentialRequest.Builder()
69
71
  .addCredentialOption(googleIdOptionFiltered)
70
72
  .build();
@@ -87,50 +89,6 @@ public class GoogleProvider implements SocialProvider {
87
89
  @Override
88
90
  public void onError(GetCredentialException e) {
89
91
  // If no authorized accounts, try again without filtering
90
- if (e instanceof NoCredentialException) {
91
- retryWithoutFiltering(call);
92
- } else {
93
- handleSignInError(e, call);
94
- }
95
- }
96
- }
97
- );
98
- }
99
-
100
- private void retryWithoutFiltering(PluginCall call) {
101
- String nonce = call.getString("nonce");
102
-
103
- GetGoogleIdOption.Builder googleIdOptionBuilder =
104
- new GetGoogleIdOption.Builder()
105
- .setFilterByAuthorizedAccounts(false)
106
- .setServerClientId(this.clientId);
107
-
108
- if (nonce != null && !nonce.isEmpty()) {
109
- googleIdOptionBuilder.setNonce(nonce);
110
- }
111
-
112
- GetGoogleIdOption googleIdOption = googleIdOptionBuilder.build();
113
- GetCredentialRequest request = new GetCredentialRequest.Builder()
114
- .addCredentialOption(googleIdOption)
115
- .build();
116
-
117
- Executor executor = Executors.newSingleThreadExecutor();
118
- credentialManager.getCredentialAsync(
119
- context,
120
- request,
121
- null,
122
- executor,
123
- new CredentialManagerCallback<
124
- GetCredentialResponse,
125
- GetCredentialException
126
- >() {
127
- @Override
128
- public void onResult(GetCredentialResponse result) {
129
- handleSignInResult(result, call);
130
- }
131
-
132
- @Override
133
- public void onError(GetCredentialException e) {
134
92
  handleSignInError(e, call);
135
93
  }
136
94
  }
@@ -19,15 +19,7 @@ class GoogleProvider {
19
19
 
20
20
  func login(payload: [String: Any], completion: @escaping (Result<GoogleLoginResponse, Error>) -> Void) {
21
21
  DispatchQueue.main.async {
22
- if GIDSignIn.sharedInstance.hasPreviousSignIn() && !self.forceAuthCode {
23
- GIDSignIn.sharedInstance.restorePreviousSignIn { user, error in
24
- if let error = error {
25
- completion(.failure(error))
26
- return
27
- }
28
- completion(.success(self.createLoginResponse(user: user!)))
29
- }
30
- } else {
22
+ func login() {
31
23
  guard let presentingVc = UIApplication.shared.windows.first?.rootViewController else {
32
24
  completion(.failure(NSError(domain: "GoogleProvider", code: 0, userInfo: [NSLocalizedDescriptionKey: "No presenting view controller found"])))
33
25
  return
@@ -49,6 +41,19 @@ class GoogleProvider {
49
41
  completion(.success(self.createLoginResponse(user: result.user)))
50
42
  }
51
43
  }
44
+
45
+ if GIDSignIn.sharedInstance.hasPreviousSignIn() && !self.forceAuthCode {
46
+ GIDSignIn.sharedInstance.restorePreviousSignIn { user, error in
47
+ if let error = error {
48
+ // completion(.failure(error))
49
+ login()
50
+ return
51
+ }
52
+ completion(.success(self.createLoginResponse(user: user!)))
53
+ }
54
+ } else {
55
+ login()
56
+ }
52
57
  }
53
58
  }
54
59
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-social-login",
3
- "version": "0.0.34",
3
+ "version": "0.0.38",
4
4
  "description": "All social logins in one plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",