Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sign In With Apple - Ionic 3

Am trying to implement sign in with apple on my ionic 3 project using the following plugin and wrapper

ionic cordova plugin add cordova-plugin-sign-in-with-apple
npm i --save @ionic-native/sign-in-with-apple

Implementation as described on the plugin docs


import { SignInWithApple, AppleSignInResponse, AppleSignInErrorResponse, ASAuthorizationAppleIDRequest } from '@ionic-native/sign-in-with-apple/ngx';


  constructor(private signInWithApple: SignInWithApple) { }


    this.signInWithApple.signin({
      requestedScopes: [
        ASAuthorizationAppleIDRequest.ASAuthorizationScopeFullName,
        ASAuthorizationAppleIDRequest.ASAuthorizationScopeEmail
      ]
    })
    .then((res: AppleSignInResponse) => {
      // https://developer.apple.com/documentation/signinwithapplerestapi/verifying_a_user
      alert('Send token to apple for verification: ' + res.identityToken);
      console.log(res);
    })
    .catch((error: AppleSignInErrorResponse) => {
      alert(error.code + ' ' + error.localizedDescription);
      console.error(error);
    });

The following error is thrown during cordova ios build process

typescript: node_modules/@ionic-native/sign-in-with-apple/ngx/index.d.ts, line: 6 
        Initializers are not allowed in ambient contexts. 

   L5:  export declare class ASAuthorizationAppleIDRequest {
   L6:      static readonly ASAuthorizationScopeFullName = 0;
   L7:      static readonly ASAuthorizationScopeEmail = 1;

Any help would be appreciated, thanks

tsc -v 
Version 3.8.3
like image 970
Arash Fahad Avatar asked Mar 28 '26 04:03

Arash Fahad


1 Answers

this work for me:

  1. install:

ionic cordova plugin add https://github.com/twogate/cordova-plugin-sign-in-with-apple.git

  1. declare var in your component

declare var cordova:any; // global

cordova.plugins.SignInWithApple.signin(
    { requestedScopes: [0, 1] },
    function(response){
      console.log(response)
      alert(JSON.stringify(response))
    },
    function(err){
      console.error(err)
      console.log(JSON.stringify(err))
}

I hope this solution can help someone.

IMPORTANT --> Test in device

like image 155
Santiago Vasquez Avatar answered Mar 30 '26 13:03

Santiago Vasquez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!