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

@easy-auth/react

v1.0.39

Published

The React package for [easy-auth](https://ice-milo.com/easy-auth/docs).

Downloads

722

Readme

About

The React package for easy-auth.

Install

npm i @easy-auth/react

yarn add @easy-auth/react

EasyAuthContextProvider

Wrap your app with EasyAuthContextProvider. Provide your API key and Google and/or Facebook app credentials so users can register and login.

import { EasyAuthContextProvider } from "@easy-auth/react";

export default function WrappedApp() {
  return (
    <EasyAuthContextProvider
      apiKey="your-api-key"
      facebookConfig={{
        appId: "your-facebook-app-id",
      }}
      firebaseConfig={{
        apiKey: "your-firebase-apiKey",
        appId: "your-firebase-appId",
        authDomain: "your-firebase-authDomain",
        projectId: "your-firebase-projectId",
      }}
    >
      <App />
    </EasyAuthContextProvider>
  );
}

Login and registration

If you'd like to use our bootstrapped components:

import { LoginPanel } from "@easy-auth/react";

export default function LoginPage() {
  return <LoginPanel />;
}

Alternatively, with useUserFlow:

import { Provider, useUserFlow } from "@easy-auth/react";
import { Button, Input } from "your-library";

export default function Login() {
  const {
    // login controls
    facebookSdkReady /** if the Facebook sdk is downloaded and has been initiated */,
    loginProvider /** the authentication-provider currently being used to login */,
    handleFacebookLogin /** calls the login API after Facebook authentication */,
    handleGoogleLogin /** calls the login API after Google authentication */,

    // registration controls
    isRegistering /** if there is an ongoing request to the register API */,
    registrationInfo /** username to be used in the current registration process */,
    newUsername /** username to be used in the registration process */,
    setNewUsername /** set the new username in the registration process */,
    handleRegister /** calls register API with registrationInfo and newUsername */,
    cancelRegistration /** cancels the current registration process */,
  } = useUserFlow();

  // Logging in with any provider will trigger the registration flow (set registrationInfo) if there is no existing Easy-Auth user

  return (
    <main>
      {registrationInfo ? (
        <div>
          <h3>Register</h3>
          <Input value={newUsername} onChange={setNewUsername} />
          <Button onClick={handleRegister} disabled={isRegistering}>
            Register
          </Button>
          <Button onClick={cancelRegistration} disabled={isRegistering}>
            Cancel
          </Button>
        </div>
      ) : (
        <div>
          <h3>Login</h3>
          <Button
            onClick={handleGoogleLogin}
            loading={loginProvider === Provider.GOOGLE}
            disabled={Boolean(loginProvider)}
          >
            Login with Google
          </Button>
          <Button
            onClick={handleFacebookLogin}
            loading={loginProvider === Provider.FACEBOOK}
            disabled={Boolean(loginProvider) || !facebookSdkReady}
          >
            Login with Facebook
          </Button>
        </div>
      )}
    </main>
  );
}

Access user information

In the rest of your app, access user information and logout as such:

import { useEasyAuthContext } from "@easy-auth/react";

export default function App() {
  const { user, logout } = useEasyAuthContext();

  return (
    <main>
      <h3>Logged in as {user.username}</h3>
      <br />
      <button onClick={logout}>Logout</button>
    </main>
  );
}

The user object will have the following shape:

interface EasyAuthUser {
  id: string;
  provider: "Google" | "Facebook";
  providerId: string;
  domain: string;
  username: string;
  createdAt: number; // unix epoch time
  contents: Record<string, any>;
}

Deregister user

When users deregister, they are for marked deletion without immediately being deleted. After a grace-period of 30 days, their information will be deleted. By logging in again (same provider, domain, & provider-id), the users marked-for-deletion will be un-marked.

import { useEasyAuthContext } from "@easy-auth/react";

export default function DeregisterButton() {
  const { deregister } = useEasyAuthContext();

  return <button onClick={deregister}>Deregister</button>;
}