diff --git a/README.md b/README.md index 67bec5b..c455c9b 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,10 @@ plugin first use `androidClientId` if not found use `clientId` if not found use ``` +Changing Play Services Auth version (Optional) : + +This plugin uses `com.google.android.gms:play-services-auth:21.2.0` by default, you can override it providing `gmsPlayServicesAuthVersion` at `variables.gradle` + **Refresh method** 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. diff --git a/android/build.gradle b/android/build.gradle index 4bb66ea..8442742 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -3,6 +3,7 @@ ext { androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1' androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5' androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1' + gmsPlayServicesAuthVersion = project.hasProperty('gmsPlayServicesAuthVersion') ? rootProject.ext.gmsPlayServicesAuthVersion : '21.2.0' } buildscript { @@ -57,5 +58,5 @@ dependencies { testImplementation "junit:junit:$junitVersion" androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion" androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion" - implementation 'com.google.android.gms:play-services-auth:18.+' + implementation "com.google.android.gms:play-services-auth:$gmsPlayServicesAuthVersion" } diff --git a/android/src/main/java/com/codetrixstudio/capacitor/GoogleAuth/GoogleAuth.java b/android/src/main/java/com/codetrixstudio/capacitor/GoogleAuth/GoogleAuth.java index 147fac8..f01f8b7 100644 --- a/android/src/main/java/com/codetrixstudio/capacitor/GoogleAuth/GoogleAuth.java +++ b/android/src/main/java/com/codetrixstudio/capacitor/GoogleAuth/GoogleAuth.java @@ -78,6 +78,10 @@ public void load() {} @PluginMethod() public void signIn(PluginCall call) { + if(googleSignInClient == null){ + rejectWithNullClientError(call); + return; + } Intent signInIntent = googleSignInClient.getSignInIntent(); startActivityForResult(call, signInIntent, "signInResult"); } @@ -155,6 +159,10 @@ public void refresh(final PluginCall call) { @PluginMethod() public void signOut(final PluginCall call) { + if(googleSignInClient == null){ + rejectWithNullClientError(call); + return; + } googleSignInClient.signOut() .addOnSuccessListener(getActivity(), new OnSuccessListener() { @Override @@ -257,4 +265,8 @@ private static String fromStream(InputStream is) throws IOException { reader.close(); return sb.toString(); } + + private void rejectWithNullClientError(final PluginCall call) { + call.reject("Google services are not ready. Please call initialize() first"); + } } diff --git a/package-lock.json b/package-lock.json index 67e7150..005d601 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@codetrix-studio/capacitor-google-auth", - "version": "3.4.0-rc.1", + "version": "3.4.0-rc.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@codetrix-studio/capacitor-google-auth", - "version": "3.4.0-rc.1", + "version": "3.4.0-rc.4", "license": "MIT", "devDependencies": { "@capacitor/android": "^6.0.0", @@ -1212,4 +1212,4 @@ } } } -} \ No newline at end of file +}