Skip to content

Instantly share code, notes, and snippets.

@zendevil
Created April 9, 2021 08:14
Show Gist options
  • Save zendevil/704508e46017910cfcdfda28768e89ec to your computer and use it in GitHub Desktop.
Save zendevil/704508e46017910cfcdfda28768e89ec to your computer and use it in GitHub Desktop.
appleAuth js
import { appleAuth } from '@invertase/react-native-apple-authentication';
async function onAppleButtonPress() {
// performs login request
const appleAuthRequestResponse = await appleAuth.performRequest({
requestedOperation: appleAuth.Operation.LOGIN,
requestedScopes: [appleAuth.Scope.EMAIL, appleAuth.Scope.FULL_NAME],
});
// get current authentication state for user
// /!\ This method must be tested on a real device. On the iOS simulator it always throws an error.
const credentialState = await appleAuth.getCredentialStateForUser(appleAuthRequestResponse.user);
// use credentialState response to ensure the user is authenticated
if (credentialState === appleAuth.State.AUTHORIZED) {
// user is authenticated
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment