Skip to content

Commit e808d9e

Browse files
authored
refactor: Improvement/bump gms google auth version (#382)
* allow supplying play services auth version & set default to 21.2.0 * update package.lock json to match current version * check for nullclients on sign-in & sign-out * correctly return void after nullClient errors
1 parent fdee173 commit e808d9e

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ plugin first use `androidClientId` if not found use `clientId` if not found use
170170
</resources>
171171
```
172172

173+
Changing Play Services Auth version (Optional) :
174+
175+
This plugin uses `com.google.android.gms:play-services-auth:21.2.0` by default, you can override it providing `gmsPlayServicesAuthVersion` at `variables.gradle`
176+
173177
**Refresh method**
174178

175179
This method should be called when the app is initialized to establish if the user is currently logged in. If true, the method will return an accessToken, idToken and an empty refreshToken.

android/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ext {
33
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
44
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
55
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
6+
gmsPlayServicesAuthVersion = project.hasProperty('gmsPlayServicesAuthVersion') ? rootProject.ext.gmsPlayServicesAuthVersion : '21.2.0'
67
}
78

89
buildscript {
@@ -57,5 +58,5 @@ dependencies {
5758
testImplementation "junit:junit:$junitVersion"
5859
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
5960
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
60-
implementation 'com.google.android.gms:play-services-auth:18.+'
61+
implementation "com.google.android.gms:play-services-auth:$gmsPlayServicesAuthVersion"
6162
}

android/src/main/java/com/codetrixstudio/capacitor/GoogleAuth/GoogleAuth.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public void load() {}
7878

7979
@PluginMethod()
8080
public void signIn(PluginCall call) {
81+
if(googleSignInClient == null){
82+
rejectWithNullClientError(call);
83+
return;
84+
}
8185
Intent signInIntent = googleSignInClient.getSignInIntent();
8286
startActivityForResult(call, signInIntent, "signInResult");
8387
}
@@ -155,6 +159,10 @@ public void refresh(final PluginCall call) {
155159

156160
@PluginMethod()
157161
public void signOut(final PluginCall call) {
162+
if(googleSignInClient == null){
163+
rejectWithNullClientError(call);
164+
return;
165+
}
158166
googleSignInClient.signOut()
159167
.addOnSuccessListener(getActivity(), new OnSuccessListener<Void>() {
160168
@Override
@@ -257,4 +265,8 @@ private static String fromStream(InputStream is) throws IOException {
257265
reader.close();
258266
return sb.toString();
259267
}
268+
269+
private void rejectWithNullClientError(final PluginCall call) {
270+
call.reject("Google services are not ready. Please call initialize() first");
271+
}
260272
}

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)