@appello/mobile
Version:
Common package with many useful features for mobile development
25 lines (24 loc) • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useAppleSignIn = void 0;
const react_native_apple_authentication_1 = require("@invertase/react-native-apple-authentication");
const react_1 = require("react");
function useAppleSignIn(onSuccess, onError) {
const signIn = (0, react_1.useCallback)(async () => {
try {
const { authorizationCode } = await react_native_apple_authentication_1.appleAuth.performRequest({
requestedOperation: react_native_apple_authentication_1.appleAuth.Operation.LOGIN,
requestedScopes: [react_native_apple_authentication_1.appleAuth.Scope.EMAIL, react_native_apple_authentication_1.appleAuth.Scope.FULL_NAME],
});
if (!authorizationCode) {
throw new Error('{authorizationCode} is falsy in {useAppleSignIn}');
}
onSuccess(authorizationCode);
}
catch (e) {
onError === null || onError === void 0 ? void 0 : onError(e);
}
}, [onError, onSuccess]);
return [signIn];
}
exports.useAppleSignIn = useAppleSignIn;