npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bundly/ares-react-native

v0.2.0

Published

Welcome to ic-react-native!

Downloads

147

Readme

ares-react-native

Provides Internet Identity Middleware provider and Auth Buttons to enable the Internet Identity integration for React Native Apps.

NOTE: This is a Beta version

How to use

Since Ares React Native depends on React Native, you must first implement Ares Core and Ares React. You can see how to do this in their README.md files.

To use Ares React Native, you must import ReactNativeStorage:

import { ReactNativeStorage } from "@bundly/ares-react-native";

const client = Client.create({
  agentConfig: {
    host: EXPO_PUBLIC_IC_HOST_URL,
  },
  candidCanisters,
  storage: new ReactNativeStorage(),
});

Maybe you need to add some polyfills, here we provide a base shim.js file that you can use and customize:

// import { polyfill as polyfillBase64 } from "react-native-polyfill-globals/src/base64";
import { polyfill as polyfillCrypto } from "react-native-polyfill-globals/src/crypto";
import { polyfill as polyfillEncoding } from "react-native-polyfill-globals/src/encoding";
// import { polyfill as polyfillFetch } from "react-native-polyfill-globals/src/fetch";
// import { polyfill as polyfillReadableStream } from "react-native-polyfill-globals/src/readable-stream";
import { polyfill as polyfillURL } from "react-native-polyfill-globals/src/url";

// polyfillBase64();
polyfillCrypto();
polyfillEncoding();
// polyfillFetch();
// polyfillReadableStream();
polyfillURL();

/**
 * Polify BigInt.toJSON for react-native
 * @returns {number}
 */
BigInt.prototype.toJSON = function () {
  return Number(this.toString());
};

if (typeof BigInt === "undefined") global.BigInt = require("big-integer");

// Polyfill for performance.now() on Android
if (!global.performance && global._chronoNow) {
  global.performance = {
    now: global._chronoNow,
  };
}

Note: This file must be imported in the highest component (e.g. index.js).

Implement Internet Identity

This package also provides an Internet Identity provider compatible with React Native applications, this provider should be importend and implemented into Client:

import * as WebBrowser from "expo-web-browser";

import { InternetIdentityReactNative, ReactNativeStorage } from "@bundly/ares-react-native";

const Browser: AppBrowser = {
  open: (url: string) => {
    WebBrowser.openBrowserAsync(url, { showTitle: false });
  },
  close: () => {
    if (["iOS", "iPadOS"].includes(Device.osName || "")) {
      WebBrowser.dismissBrowser();
    }
  },
};

const client = Client.create({
  agentConfig: {
    host: EXPO_PUBLIC_IC_HOST_URL,
  },
  candidCanisters,
  providers: [
    new InternetIdentityReactNative({
      providerUrl: EXPO_PUBLIC_INTERNET_IDENTITY_MIDDLEWARE_URL!,
      appLink: `${EXPO_PUBLIC_APP_LINK}`,
      browser: Browser,
    }),
  ],
  storage: new ReactNativeStorage(),
});

Because Internet Identity is an application that only works with web apps, you need to implement middleware that can catch the identity generated by Internet Identity and return it to the React Native application.

An example in this repo is Internet Identity Middleware.

Now you can use the Internet Identity Middleware Button to log in your users:

import { InternetIdentityMidlewareButton, LogoutButton } from "@bundly/ares-react-native";

<InternetIdentityMidlewareButton />;

You can see a full implementation in this repository: motoko-react-native.