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

Unable to build IOS version of the app #24

Open jorgementx opened 1 month ago

jorgementx commented 1 month ago

The IOS version has an error in the Swift codebase that gets thrown at compile time:

Captura de pantalla 2024-10-14 a las 10 45 30

The solution for me at the moment is using @codetrix-studio/capacitor-google-auth just for the IOS version of the app, and everytime I run ionic cap build ios removing the dependency of capacitor-native-google-one-tap-signin by removing the following line from the frontend/ios/App/Podfile:

pod 'CapacitorNativeGoogleOneTapSignin', :path => '../../node_modules/capacitor-native-google-one-tap-signin'

and running pod update inside frontend/ios/App.

I know it's not a great solution (but at least gets the job done) and that's why I would like to use just this plugin to handle social auth with google.

inouiw commented 1 month ago

Hi @jorgementx,

thank you for posting the issue and for using the plugin. Can you provide the steps to reproduce the issue? When I checkout the repository and then run

cd ios
pod install
open Plugin.xcworkspace

Then Xcode opens and I can successfully build the iOS project. In Xcode under Signing & Capabilities I have selected my signing certificate.

image

There is also an automated test (github action) for this repository that compiles the ios code and runs ios tests. It is to make sure that the iOS code compiles and has no errors. When you run npm run test:ios then the iOS code is build and the tests are run in a iOS simulator "iPhone 15,OS=17.5". To run the tests make sure the simulator is installed and that under Team, your signing certificate is set as in the screenshot above.

Would like to hear if you can get it to run without code changes and maybe you have suggestions for improvement.

inouiw commented 1 month ago

Note that to use the plugin in your ionic project, you do not need to compile the iOS project. You can just add the npm package to your project.

jorgementx commented 1 month ago

Following the steps provided above I still get the error. The only way i can make it to work is by installing/updating pods without this dependency.

Some extra infromation in case it is useful:

  1. I am using the last version of the package, 6.1.6.
  2. I am trying to build for 2 devices: a physical iphone 7 Plus with ios 15 and a virtual iphone 15 pro max with ios 17. I get the same error with both.

If you can think of any other information that migth be useful don't hesitate to ask for it

inouiw commented 1 month ago

Can you check if you are using the latest version of the code. In the screenshot below the iOS Plugin name is "Plugin" but in your screenshot it is "CapacitorNativeGoogleOneTapSignin"?

image

jorgementx commented 4 weeks ago

I'm sorry I forgot to respond earlier. After checking the package-lock.json and the node_modules just to make sure, I can confirm I'm currently using the last version of the package (6.1.6). Inside node_modules where your project lives the folder name is Plugin but I'm guessing that after installing in another app the name that is used is the one you set inside the package.json, which is "capacitor-native-google-one-tap-signin".

Edit: After typing all this I realized that you published a new version, should I try with that one?

inouiw commented 2 weeks ago

@jorgementx, can you try the following:

# ensure ionic is installed and up to date
npm install -g @ionic/cli

# create a new ionic project
ionic start testOneTap blank --type=react

# go to the created directory
cd ./testOneTap

# install this plugin
npm i --save capacitor-native-google-one-tap-signin

# add ios support
npm install @capacitor/ios

# build & sync
npm run build
npx cap update

# open xcode
npx cap open ios

Now run the app in xcode to see if it is working.

Then you can edit Home.tsx as floows to check if you get the id token.

import React from 'react';
import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar, IonButton } from '@ionic/react';
import { GoogleOneTapAuth } from 'capacitor-native-google-one-tap-signin';
import './Home.css';

const Home: React.FC = () => {
  const clientId = '333448133894-m88bqcrq93ao7vi2j4o475fnlbsnhc9g.apps.googleusercontent.com';

  const handleClick = async () => {

    void GoogleOneTapAuth.initialize({ clientId: clientId });

    // Trigger auto sign-in and if not successful try one-tap sign-in.
    let signInResultOption = await GoogleOneTapAuth.tryAutoOrOneTapSignIn();

    if (signInResultOption.isSuccess === false) {
      // Start the sign-in with button flow.
      signInResultOption = await GoogleOneTapAuth.signInWithGoogleButtonFlowForNativePlatform();
    }
    console.log(signInResultOption);
  };

  return (
    <IonPage>
      <IonHeader>
        <IonToolbar>
          <IonTitle>Home</IonTitle>
        </IonToolbar>
      </IonHeader>
      <IonContent className="ion-padding">
        <IonButton onClick={handleClick}>Trigger signInWithGoogleButtonFlowForNativePlatform</IonButton>
      </IonContent>
    </IonPage>
  );
};

export default Home;
# Build and sync
npm run build
npx cap sync

Start the app in xcode to see if you get the idToken displayed (in xcode) if you click the button.