@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
62 lines (59 loc) • 2.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PassageOneTimePasscode = void 0;
var _index = require("../shared/index.js");
/**
* PassageOneTimePasscode class contains functions that use one-time passcodes for authentication.
*/
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 _index.PassageReactNative.oneTimePasscodeRegister(identifier, language || null);
const parsedResult = JSON.parse(result);
return parsedResult;
} catch (error) {
throw new _index.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 _index.PassageReactNative.oneTimePasscodeLogin(identifier, language || null);
const parsedResult = JSON.parse(result);
return parsedResult;
} catch (error) {
throw new _index.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 _index.PassageReactNative.oneTimePasscodeActivate(oneTimePasscode, id);
const parsedResult = JSON.parse(result);
return parsedResult;
} catch (error) {
throw new _index.PassageError(error.code, error.message);
}
}
}
exports.PassageOneTimePasscode = PassageOneTimePasscode;
//# sourceMappingURL=PassageOneTimePasscode.js.map