0.0.1 • Published 2 years ago

@vizibr/use-security v0.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

check

@platformbuilders/use-security

Install

yarn add @platformbuilders/use-security

Install Dependencies

yarn add jail-monkey react-native-check-version react-native-device-info react-native-exit-app

Usage

checkUpdate

import React, { useEffect } from 'react';
import RNExitApp from 'react-native-exit-app';
import { useSecurity } from '@platformbuilders/use-security';

const Example = () => {
  const { checkUpdate } = useSecurity();

  checkVersion = async (): Promise<void> => {
    const { isNeeded, storeUrl } = await checkUpdate();
    const title = 'Atualização disponível';
    const message = 'É necessário atualizar o app para continuar utilizando!';
    const buttonText = 'Atualizar';
    if (isNeeded && storeUrl) {
      Alert.alert(title, message, [
        {
          text: buttonText,
          onPress: () => {
            RNExitApp.exitApp();
            Linking.openURL(storeUrl);
          },
        },
      ]);
    }
  };

  useEffect(() => {
    checkVersion();
  }, []);
};

checkEmulator

import { useSecurity } from '@platformbuilders/use-security';

const Example = () => {
  const { checkEmulator } = useSecurity();

  checkEmulator = async (): Promise<void> => {
    const isEmulator = await checkEmulator();
    if (isEmulator) {
      // do something
    }
  };

  useEffect(() => {
    checkEmulator();
  }, []);
};

blockEmulator

import { useSecurity } from '@platformbuilders/use-security';

const Example = () => {
  const { blockEmulator } = useSecurity();

  secureEmulator = async (): Promise<void> => {
    const isPRD = Env.ENV === 'PRD';
    if (isPRD) {
      blockEmulator();
    }
  };

  useEffect(() => {
    secureEmulator();
  }, []);
};

checkRoot

import { useSecurity } from '@platformbuilders/use-security';

const Example = () => {
  const { checkRoot } = useSecurity();

  checkRoot = async (): Promise<void> => {
    const isRooted = await checkRoot();
    if (isRooted) {
      // do something
    }
  };

  useEffect(() => {
    checkRoot();
  }, []);
};

blockRoot

import { useSecurity } from '@platformbuilders/use-security';

const Example = () => {
  const { blockRoot } = useSecurity();

  secureEmulator = async (): Promise<void> => {
    const isPRD = Env.ENV === 'PRD';
    if (isPRD) {
      blockRoot();
    }
  };

  useEffect(() => {
    secureRoot();
  }, []);
};