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

59 lines (55 loc) 1.77 kB
"use strict"; import { PassageError, PassageReactNative } from "../../src/shared/index.js"; export class PassageTokenStore { /** * Returns the auth token for the currently authenticated user. * If the stored auth token is invalid, this method will use the refresh token to get and save a new auth token. * * @return {Promise<string | null>} the valid auth token or null */ async getValidAuthToken() { try { return await PassageReactNative.tokenStoreGetValidAuthToken(); } catch (error) { throw new PassageError(error.code, error.message); } } /** * Checks validity of stored auth token. * * @return {Promise<boolean>} true if auth token is valid */ async isAuthTokenValid() { try { const result = await PassageReactNative.tokenStoreIsAuthTokenValid(); return result || false; } catch (error) { throw new PassageError(error.code, error.message); } } /** * Refreshes stored auth token. Returns updated AuthResult if successful. * * @return {Promise<AuthResult>} The authentication token, redirect URL, and refresh token, if configured for the application. */ async refreshAuthToken() { try { const result = await PassageReactNative.tokenStoreRefreshAuthToken(); const parsedResult = JSON.parse(result); return parsedResult; } catch (error) { throw new PassageError(error.code, error.message); } } /** * Revokes the current refresh token, removing it from the server. */ async revokeRefreshToken() { try { await PassageReactNative.tokenStoreRevokeRefreshToken(); } catch (error) { throw new PassageError(error.code, error.message); } } } //# sourceMappingURL=PassageTokenStore.js.map