UNPKG

@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

57 lines (54 loc) 2.46 kB
"use strict"; import { PassageError, PassageReactNative } from "../shared/index.js"; /** * PassageOneTimePasscode class contains functions that use one-time passcodes for authentication. */ export class PassageOneTimePasscode { /** * Create a new one-time passcode for registration. Will throw an error if the user has already logged into their account at least once. * @param {string} identifier The Passage User's identifier * @param {string} language the language string for localizing emails, if no lanuage or an invalid language is provided the application default lanuage will be used * @return {Promise<OneTimePasscode>} One-time passcode object */ async register(identifier, language) { try { const result = await PassageReactNative.oneTimePasscodeRegister(identifier, language || null); const parsedResult = JSON.parse(result); return parsedResult; } catch (error) { throw new PassageError(error.code, error.message); } } /** * Create a new one-time passcode for login. Will throw an error if the user does not exist. * @param {string} identifier The Passage User's identifier * @param {string} language the language string for localizing emails, if no lanuage or an invalid language is provided the application default lanuage will be used * @return {Promise<OneTimePasscode>} One-time passcode object */ async login(identifier, language) { try { const result = await PassageReactNative.oneTimePasscodeLogin(identifier, language || null); const parsedResult = JSON.parse(result); return parsedResult; } catch (error) { throw new PassageError(error.code, error.message); } } /** * Activates a one-time passcode. Handles login and registration one-time passcodes. * Will throw an error if the one-time passcode is invalid, expired, or has already been activated. * @param {string} oneTimePasscode The one-time passcode provided by the user from their email or text message. * @param {string} id The id associated with the one-time passcode. * @returns */ async activate(oneTimePasscode, id) { try { const result = await PassageReactNative.oneTimePasscodeActivate(oneTimePasscode, id); const parsedResult = JSON.parse(result); return parsedResult; } catch (error) { throw new PassageError(error.code, error.message); } } } //# sourceMappingURL=PassageOneTimePasscode.js.map