Quick start
Sign in
import { AppleSignIn } from 'nitro-apple-signin'
if (AppleSignIn.isSupported()) {
const credential = await AppleSignIn.signIn({ scopes: ['fullName', 'email'], nonce: rawNonce })
if (credential !== undefined) {
// Email and name arrive only on the first sign-in: send them with the token.
await sendToBackend(
credential.identityToken,
credential.authorizationCode,
credential.fullName,
credential.email,
)
saveUserId(credential.user)
}
}
isSupported()is synchronous:trueon iOS,falseon Android. Use it to decide whether to show the button.signInresolvesundefinedwhen the user closes the sheet. That is not an error.rawNonceis a random, single-use string you generate. See Backend verification.sendToBackendandsaveUserIdare your code.
Check the credential at launch
Users can stop using their Apple ID with your app from Settings. Check the stored user ID on launch:
const state = await AppleSignIn.getCredentialState(storedUserId)
if (state === 'revoked' || state === 'notFound') signOut()
Handle errors
import { AppleSignIn, getAppleSignInErrorCode } from 'nitro-apple-signin'
try {
await AppleSignIn.signIn()
} catch (error) {
const code = getAppleSignInErrorCode(error) // 'IN_PROGRESS', 'SIGN_IN_FAILED', ...
}
Where to go next:
- Signing in: scopes, first-sign-in data and concurrency.
- Sign-in button: a ready-made button.
- Errors and troubleshooting.