@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
64 lines (60 loc) • 1.92 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PassageTokenStore = void 0;
var _index = require("./index.js");
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 _index.PassageReactNative.tokenStoreGetValidAuthToken();
} catch (error) {
throw new _index.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 _index.PassageReactNative.tokenStoreIsAuthTokenValid();
return result || false;
} catch (error) {
throw new _index.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 _index.PassageReactNative.tokenStoreRefreshAuthToken();
const parsedResult = JSON.parse(result);
return parsedResult;
} catch (error) {
throw new _index.PassageError(error.code, error.message);
}
}
/**
* Revokes the current refresh token, removing it from the server.
*/
async revokeRefreshToken() {
try {
await _index.PassageReactNative.tokenStoreRevokeRefreshToken();
} catch (error) {
throw new _index.PassageError(error.code, error.message);
}
}
}
exports.PassageTokenStore = PassageTokenStore;
//# sourceMappingURL=PassageTokenStore.js.map
;