Giter Club home page Giter Club logo

capacitor-sign-in-with-apple's Introduction

capacitor-sign-in-with-apple

Native Sign In With Apple CapacitorJS Plugin

npm

Get your own badge

Requirements

This is only designed to work with the current version of Capacitor (4+ as of this writing).

Install

npm install @changenode/capacitor-sign-in-with-apple
npx cap sync

API

auth()

auth() => Promise<{ response: SignInWithAppleSuccess | any; }>

Returns: Promise<{ response: any; }>


Interfaces

SignInWithAppleSuccess

Prop Type
user string
state string
email string
givenName string
familyName string
identityToken string
authorizationCode string

Sample Usage

This is a snippet illustrating how I am using this code in my SvelteKit code. I imagine it's largely the same for Ionic - if anyone wants to post a snippet for Ionic feel free to do so in the GitHub Discussions and I'll include and/or link.

<script lang="ts">
	import { Capacitor } from '@capacitor/core';

	import {SignInWithApple} from 'capacitor-sign-in-with-apple';

	let device: any;
	let r: any;
	let e: any;

	async function auth() {
		device = Capacitor.getPlatform();

		SignInWithApple.auth()
			.then((response: any) => {
				console.log(response);
				r = response;
			})
			.catch((response: any) => {
				console.error(response);
				e = response;
			});
	}

	auth();
</script>

The plugin currently is only intended for use on iOS. It would be possible to implement Sign in with Apple on Android and via the web using Apple's REST and/or JavaScript SDKs, but that's out of scope for this plugin. If you do implement that functionality in another plugin let me know and I can include a link.

Errors & Troubleshooting

Unfortunately debugging issues with Sign in with Apple can be difficult. If you run into challenges with a simple "Hello World" app double-check the following:

  • The app id (e.g. com.example.my.App) is correct everywhere
  • The Sign in with Apple capability is set for the app - debug, release, etc.
  • The profiles are set up correctly in XCode
  • The app id is correctly associated with the Sign in with Apple info in the Apple developer portal

Reach out to Apple if Necessary

If everything is set up correctly you can still run into errors due to [mis]configuration on the Apple end of things. One symptom of this is the app will bring up the native dialog in the simulator and on the real device and appear to work but then fail with a large red exclaimation point and the message "Sign Up Not Completed" in the native dialog. You won't get anything in log files until you hit cancel, and then you will get a pretty generic error code that won't show up in Google searches.

As of this writing as part of your Apple Developer fee you get two dev tech support incidents. If you are certain that you have set up everything in your app correctly and you still get Sign Up Not Completed errors, I highly recommending using one of your support incidents to resolve the issue.

History

Based on the implementation by rlfrahm. I also looked through the various public forks of that branch and incorporated some of the changes I found.

Significant changes:

  • Rebuilt the project from scratch using the latest Capacitor 4 plugin generator.
  • Updated to use the most recent Swift bindings for auth from Apple
  • Added a TypeScript definition to match the resulting success data from Apple

Notes

As of this writing I'm able to use Sign in with Apple in an iPad-on-Apple Silicon build target via XCode, which is much faster/easier than using the iOS Simulator.

capacitor-sign-in-with-apple's People

Contributors

wiverson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.