UNPKG

react-native-credentials-manager

Version:

A React Native library that implements the Credential Manager API for Android. This library allows you to manage passwords and passkeys in your React Native applications.

77 lines (73 loc) 2.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.signIn = signIn; exports.signOut = signOut; exports.signUpWithApple = signUpWithApple; exports.signUpWithGoogle = signUpWithGoogle; exports.signUpWithPasskeys = signUpWithPasskeys; exports.signUpWithPassword = signUpWithPassword; var _NativeCredentialsManager = _interopRequireDefault(require("./NativeCredentialsManager.js")); var _reactNative = require("react-native"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function signUpWithPasskeys(requestJson, preferImmediatelyAvailableCredentials = false) { return _NativeCredentialsManager.default.signUpWithPasskeys(requestJson, preferImmediatelyAvailableCredentials); } function signUpWithPassword({ username, password }) { if (_reactNative.Platform.OS === 'ios') { return Promise.reject(new Error('Manual password storage is not supported on iOS. Use AutoFill passwords through signIn method instead.')); } return _NativeCredentialsManager.default.signUpWithPassword({ password, username }); } function signIn(options, params) { const signInParams = { passkeys: params.passkeys }; if (options.includes('google-signin')) { signInParams.googleSignIn = { serverClientId: params.googleSignIn?.serverClientId ?? '', nonce: params.googleSignIn?.nonce ?? '', autoSelectEnabled: params.googleSignIn?.autoSelectEnabled ?? true }; } // If we have Apple Sign In option on iOS, add Apple params if (_reactNative.Platform.OS === 'ios' && options.includes('apple-signin')) { signInParams.appleSignIn = { nonce: params.appleSignIn?.nonce ?? '', requestedScopes: params.appleSignIn?.requestedScopes ?? ['fullName', 'email'] }; } return _NativeCredentialsManager.default.signIn([...options], signInParams); } function signUpWithGoogle(params) { if (_reactNative.Platform.OS === 'ios') { return Promise.reject(new Error('Google Sign In is only available on Android. Use signUpWithApple on iOS.')); } return _NativeCredentialsManager.default.signUpWithGoogle({ ...params, nonce: params.nonce ?? '', autoSelectEnabled: params.autoSelectEnabled ?? true }); } function signUpWithApple(params = {}) { if (_reactNative.Platform.OS !== 'ios') { return Promise.reject(new Error('Apple Sign In is only available on iOS. Use signUpWithGoogle on Android.')); } // Call the native signUpWithApple method directly - uses Apple's Authentication Services return _NativeCredentialsManager.default.signUpWithApple({ nonce: params.nonce || '', requestedScopes: params.requestedScopes || ['fullName', 'email'] }); } function signOut() { return _NativeCredentialsManager.default.signOut(); } // Export types //# sourceMappingURL=index.js.map