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

36 lines (35 loc) 1.45 kB
"use strict"; import { Platform } from 'react-native'; import { PassageError, PassageReactNative, waitForDeepLinkQueryValues } from "../shared/index.js"; /** * PassageSocial class contains functions that use social providers for authentication. */ export class PassageSocial { /** * Initiates authorization via a supported third-party social provider. * @param {SocialConnection} connection The social connection to use for login. */ async authorize(connection) { return new Promise(async (resolve, reject) => { try { let authResultJson; if (Platform.OS === 'ios') { // The iOS native "authorize" method returns an AuthResult directly. authResultJson = await PassageReactNative.socialAuthorize(connection); } else { // The Android native "authorize" method opens a Chrome Tab and returns void. await PassageReactNative.socialAuthorize(connection); // Wait for a redirect back into the app with the auth code. const authCodeObj = await waitForDeepLinkQueryValues(['code']); const authCode = authCodeObj.code; authResultJson = await PassageReactNative.socialFinish(authCode); } const authResult = JSON.parse(authResultJson); resolve(authResult); } catch (error) { reject(new PassageError(error.code, error.message)); } }); } } //# sourceMappingURL=PassageSocial.js.map