Sign In with apple for ionic 4

Please, help me find a solution for Sign In with apple for ionic 4. I tried`

I found the solution

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);
});
4 Likes

Does anyone know how to logout after you sign in with apple

I am getting this error

HomePage.html:10 ERROR TypeError: Object(…) is not a function
at SignInWithApple.signin (vendor.js:80215)

Any solution for this?

Did you find logout solution?

no, still looking for it. if u found a solution please let me know

AngularFireAuth logout function works well:

this.afAuth.auth.signOut();

Do we need more? :confused:

Hi, there’s a nice tutorial in medium, I followed it and it worked like a charm

There is also one for the app, not only for web

when i try to import as follows

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

it’s giving me following errors

[21:48:03] typescript: node_modules/@ionic-native/sign-in-with-apple/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;

[21:48:03] typescript: node_modules/@ionic-native/sign-in-with-apple/index.d.ts, line: 7
Initializers are not allowed in ambient contexts.

   L6:  static readonly ASAuthorizationScopeFullName = 0;
   L7:  static readonly ASAuthorizationScopeEmail = 1;
   L8:  requestedScopes?: number[];

Hi everyone,
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.

1 Like