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

react-modern-auth

v1.0.5

Published

A plug-n-play authentication component for React with log in and sign up pages. Powered by the backend of your choice via custom callbacks.

Downloads

16

Readme

React Modern Auth

A plug-n-play authentication component for React with log in and sign up pages. Powered by the backend of your choice via custom callbacks.

Features include:

  • Customisable sign-up fields
  • Optional SSO providers
  • Password reset requesting
  • Mobile-first responsive design
  • Built-in sign-up form validation

Usage

import {
  ReactModernAuth,
  AuthConfig,
  SignUpData,
} from "react-modern-auth";
import LoadingSpinner from "./components/LoadingSpinner";
import useAuth from "./hooks/useAuth";

export default function App() {
  const { isLoading } = useAuth();
  const authConfig: AuthConfig = {
    signUpFields: [
      {
        type: "name",
        required: true,
      },
      {
        type: "email",
        required: true
      },
    ],
    enableSignUpValidation: true,
    handlers: {
      authWithPassword: async (email: string, password: string) => {
        // Pass on to your backend and return an AuthResponse object
        return { success: true };
      },
      signUp: async (data: SignUpData) => {
        // Pass on to your backend and return a SignUpResponse object
        return { success: true };
      },
      requestPasswordReset: async (email: string) => {
        // Handle password reset request
      }
    }
  }

  return (
    <ReactModernAuth
      config={authConfig}
      isLoading={isLoading}
      loadingComponent={<LoadingSpinner />}
    />
  );
}

AuthConfig options

signUpFields

Sign up fields are defined by one of the following: | Type | Input Type | Parameters | Description | |----------------------|------------|------------|-------------| | email (optional) | text | required: boolean | | | name (optional) | text | required: boolean | | | firstName (optional) | text | required: boolean | If provided, lastName is also required and they will be rendered side-by-side. | | lastName (optional) | text | required: boolean | If provided, firstName is also required and they will be rendered side-by-side. | | username (optional) | text | required: boolean | | | avatar (optional) | file | required: boolean, maxMB: number | maxMB can be specified to limit the size of the file attached. | | termsAccepted (optional) | checkbox | privacyPolicyURL: string, termsAndConditionsURL: string | Links to privacyPolicyURL and/or termsAndConditionsURL can be provided. Field required if validation is enabled. | | password | password | | Must be longer than 8 characters if validation is enabled. Does not need to be included in authConfig.signUpFields since it is non-optional. | | passwordConfirm | password | | Must match the password field if validation is enabled. Does not need to be included in authConfig.signUpFields since it is non-optional. |

Each field can be included as an object in the following form:

{
  type: "<field type>",
  required: true/false,
  otherParameter: "<value>"
}

enableSignUpValidation

A boolean flag to automatically validate form fields on sign up. Defaults to false, in which case you can provide your own validation by returning errors from your signUp handler for each field. See the handlers section for details.

oAuthProviders

An array of oAuth SSO providers. If empty, the option will not be given to authenticate using SSO. If you choose to provide options for SSO, they should be included as objects of the following form:

{
  name: string, // The name of the provider. This will be passed to your authWithOAuth handler in the `provider` argument.
  logoSrc: string // The location of an image to present to the user.
}

handlers

The following handlers are how you deal with user interaction: | Handler | Parameters | Return type | Description | |-----------------|------------|-------------|-------------| | authWithPassword | email: string, password: string | AuthResponse | | | authWithOAuth (optional) | provider: string | AuthResponse | provider will be one of the names you configured in the oAuthProviders | | signUp | data: SignUpData | SignUpResponse | | | requestPasswordReset | email: string | void | |

Handler Responses

AuthResponse
{
 success: boolean,
 error?: {
   type: string, // ie email, username, password, general
   message: string
 }
}
SignUpResponse
{
  success: boolean,
  errors?: [
    {
      type: string // eg name, email, password, general, etc
      message: string
    }
  ]
}

theme

Optionally, a theme can be provided to modify the primaryColor and accentColor of the UI. It takes the form:

{
  primaryColor: "#abc123", // Color of the buttons
  accentColor: "#abc123" // Color of the input accent and SSO provider containers
}