Closed felixkrautschuk closed 1 year ago
Thank you @felixkrautschuk I'm looking into this!
@felixkrautschuk make sure your Info.plist contains the following required key (this is required now), repace {your-client-id}
with yours according to GoogleService-Info.plist:
<key>GIDClientID</key>
<string>{your-client-id}.apps.googleusercontent.com</string>
And also, as usual the reverse client scheme as well, eg:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>REVERSED_CLIENT_ID</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.{your-client-id}</string>
</array>
</dict>
</array>
Also be sure you have called configure
in main.ts
(or app.ts
depending on project type), eg:
import { GoogleSignin } from '@nativescript/google-signin';
GoogleSignin.configure();
With those in place, I see a valid user returned:
const user = await GoogleSignin.signIn();
console.log('displayName:', user.displayName); // 'My Valid Account Name'
console.log('idToken:', user.idToken); // 'eyJhbGciOiJSUzI1NiIsImtpZCI6Ijg...' (complete idToken)
@NathanWalker thanks for your reply.
On iOS, the issue does not occur. I already added the GIDClientID to Info.plist, everything is working there.
Only Android is affected. It was working with v. 1.0.1, but after upgrading to 2.0.2, the user object is always null.
We're going to move the .kt
source to directly inside the plugin to regen latest, looking at Android.
Hi @felixkrautschuk when you get a chance, could you try setting package to 2.0.4
and then ns clean
. Should resolve Android but let us know.
@NathanWalker thank you for the fix! I can confirm that it s working now on Android.
In Android, the activity context is not available until after the application's main activity has been created. If the GoogleSignin.configure() method requires the Android activity context, it must be called after the activity is created. I'm trying to find the correct placement. Maybe I could call it from a component once created has been called.
I'm using vue, but since GoogleSignin.configure() method requires the Android activity context, and must be called after the activity is created, I made a service file:
import { GoogleSignin } from '@nativescript/google-signin'
async function configureGoogle() {
try {
// Configure Google Sign-In
await GoogleSignin.configure()
console.log('Google Sign-In configured')
} catch(error) {
console.log('Error during configuration', error)
}
}
async function signInWithGoogle() {
let user = null
try {
user = await GoogleSignin.signIn()
console.log(user)
} catch(error) {
console.log('Error during sign in', error)
}
return user
}
export { configureGoogle, signInWithGoogle }
Then in my component initialization (in my case, App.vue created () function), I call the configure().
Then, on my button or wherever you want to have the login, just call the signInWithGoogle(). Worked like a charm. I'm still curious however on how to wait for the activity to finish. I'll look into it.
You can listen to the activityCreated event
Application.android.on('activityCreated', (args) => {
console.log('activityCreated');
GoogleSignin.configure();
});
After upgrading @nativescript/google-signin from 1.0.1 to 2.0.2, the user object inside the Promise of the signIn method is always null.
Using version 1.0.1, this worked as expected.
In the launchEvent, I call configure like this:
I am passing an empty object, as the web-client-id is already set as _default_web_clientid inside the strings.xml