inouiw / capacitor-native-google-one-tap-signin

Wraps native android One Tap sign-in api for ionic capacitor apps
MIT License
10 stars 4 forks source link

from web its giving error #11

Closed tarangshah19 closed 1 year ago

tarangshah19 commented 1 year ago

when i try this with web its giving me follwing error

Error: Assert error, expected '() => !!parentElem' to be true. at assert (helpers.ts:6:11) at GoogleOneTapAuth.renderSignInButton (GoogleOneTapAuth.ts:82:5) at async logIns (AuthProvider.vue:33:1)

But in android is working fin

But in android after 2 to 3 times auto login its not ask google id

onMounted(async () => { GoogleAuth.initialize(); await GoogleOneTapAuth.initialize({ clientId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com' }); })

async function logIns() { try { const signInResult = await GoogleOneTapAuth.tryAutoOrOneTapSignIn() .then(res => res.signInResultOptionPromise); if (signInResult.isSuccess) { console.log(signInResult.success); token.value = signInResult?.success?.idToken firstName.value = signInResult?.success?.decodedIdToken?.given_name lastname.value = signInResult?.success?.decodedIdToken?.familyName await postGoogle() } else { const successResult = await GoogleOneTapAuth .renderSignInButton('google-signin', {}, { text: 'continue_with' }); console.log('successResult',successResult); } //const response = await GoogleAuth.signIn(); // token.value = response?.authentication?.idToken

// firstName.value = response?.givenName // lastname.value = response?.familyName

// await postGoogle()

const data = { firstName : firstName.value, lastname: lastname.value } await store.dispatch("auth/getSocialLoginData", data); }catch(e) { console.log(e) }

}

inouiw commented 1 year ago

Hi @tarangshah19,

concerning Error: Assert error, expected '() => !!parentElem' to be true.. The error is thrown if the element cannot be found. See https://github.com/inouiw/capacitor-native-google-one-tap-signin/blob/a42e1dd4b111efadfff7db5400c6ecab25d4c227/src/GoogleOneTapAuth.ts#L82 Since you are passing 'google-signin', ensure that document.getElementById('google-signin') returns an element and not undefined when calling renderSignInButton.

Concerning "But in android after 2 to 3 times auto login its not ask google id". Maybe you can describe in more detail what you mean. There was the issue https://github.com/inouiw/capacitor-native-google-one-tap-signin/issues/8 I fixed it but did not merge and create a new package yet. Will do that now. With the #8 Fix there is a new method addSignInActionToExistingButton that allows you to create your own Login button, and use this library to add a listener to it. You can reattach the listener if the promise is resolved.

Note that in the /demo folder there is a react demo project where you can see how to use the library.

inouiw commented 1 year ago

Version 5.1.0 is now published.

inouiw commented 1 year ago

Will close this issue. In case there is still a problem please reopen this issue or create a new one.