@passageidentity/passage-react-native
Version:
Passkey Complete for React Native - Go completely passwordless with a standalone auth solution in your React Native app with Passage by 1Password
61 lines (58 loc) • 2.28 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PassagePasskey = void 0;
var _reactNative = require("react-native");
var _index = require("../shared/index.js");
/**
* PassagePasskey class contains functions that use passkeys for authentication.
*/
class PassagePasskey {
/**
* Registers a new user with a passkey. Will throw an error if the user has already logged into their account at lesst once.
* @param {string} identifier
* @param {PasskeyCreationOptions | undefined} options
* @returns {AuthResult} The authentication token, redirect URL, and refresh token, if configured for the application.
*/
async register(identifier, options) {
try {
const result = await _index.PassageReactNative.passkeyRegister(identifier, options || null);
const parsedResult = JSON.parse(result);
return parsedResult;
} catch (error) {
throw new _index.PassageError(error.code, error.message);
}
}
/**
* Logs in an existing user with a passkey. Will throw an error if the user does not exist, has no passkeys, or if the operation is cancelled with an abort signal.
* If no identifier is provided, the user will be prompted to select an identifier, formally known as WebAuthn discoverable credentials.
* @param {string} identifier
* @returns {AuthResult} The authentication token, redirect URL, and refresh token, if configured for the application.
*/
async login(identifier) {
try {
const result = await _index.PassageReactNative.passkeyLogin(identifier || null);
const parsedResult = JSON.parse(result);
return parsedResult;
} catch (error) {
throw new _index.PassageError(error.code, error.message);
}
}
/**
* Checks if the user's device supports passkeys.
*/
isSupported() {
if (_reactNative.Platform.OS === 'ios') {
const iosVersion = parseFloat(_reactNative.Platform.Version);
return iosVersion >= 16;
} else if (_reactNative.Platform.OS === 'android') {
const androidVersion = _reactNative.Platform.Version;
return androidVersion >= 28;
} else {
return false; // Unsupported platform
}
}
}
exports.PassagePasskey = PassagePasskey;
//# sourceMappingURL=PassagePasskey.js.map
;