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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@config.one/auth

v1.2.15

Published

A set of auth react components for Config.one Platform

Downloads

139

Readme

Foo

@config.one/auth

NPM JavaScript Style Guide

Contents

Install

npm i @config.one/auth

Get started

import React, { Component } from 'react';
import { AuthProvider, Registration } from '@config.one/auth';

const config = {
  paths: {
    base:     'http://127.0.0.1:8000',
    register: '/api/public/v1/user/register',
  },
  dev: true,
};

class Example extends Component {
  onSuccess = (values, response) => {
    console.log('Registration successful', values);
  };
  
  onFailure = response => {
    console.log('Registration failed!', response);
  };
  
  onLoginClick = () => {
    console.log('Login button clicked!');  
  };

  render () {
    return (
      <AuthProvider config={config}>
        <Registration 
          onSuccess={this.onSuccess}
          onFailure={this.onFailure}
          onLoginClick={this.onLoginClick}
        />
      </AuthProvider>
    )
  }
}

Configuration

./config.js
export default {
    paths: {
        // Base path will be prepended to each path.
        // If not specified, the current location will be used.
        base:               'http://127.0.0.1:8000/',
        
        // Used by the Registration component.
        domainList:         '/api/public/v1/domain/list',
        register:           '/api/public/v1/user/register',
        
        // Used by the Login component.
        token:              '/api/public/token',
        userProfile:        '/api/secure/v1/user/profile',
        
        // Used by the PasswordReset component.
        emailRequestReset:  '/api/public/v1/user/reset_password/email/start',
        
        // You can specify an absolute path. It will ignore the base path.
        // Used by the PhoneActivation component.
        phoneActivate:      'http://config.one/api/secure/v1/user/phone/activate',
    },
    // If true, some usefull verbose information will be shown in the browser console.
    dev: true,
}

None of the configuration entries are required. The default configuration is:

const config = {
  paths: {
      domainList:         '/api/public/v1/domain/list',
      register:           '/api/public/v1/user/register',
      token:              '/api/public/token',
      emailRequestReset:  '/api/public/v1/user/reset_password/email/start',
      phoneActivate:      '/api/secure/v1/user/phone/activate',
      userProfile:        '/api/secure/v1/user/profile'
  },
  dev: false
}

Helpers

createAxios

@config.one/auth uses axios under the hood to make remote requests. The createAxios helper takes a single argument, which is a user config and returns an instance of axios. It intercepts all requests with the status code 401 (Unauthorized) and tries to refresh the access_token before any .then() and catch(). If there were other parallel requests, they are stalled into a queue until the new access_token is retrieved. You should also pass with instance to the AuthProvider component, so that both your project components and the plugin components could use the same instance of axios.

import { AuthProvider, createAxios } from '@config.one/auth';
import config from './config';

// Create an auth aware axios instance
const axios = createAxios(config);

const App = () => (
    <AuthProvider config={config} tokenAwareAxios={axios}>
        ...
    </AuthProvider>
)

Components

AuthProvider

All components should be wrapped into AuthProvider component to have access to users configuration and to axios instance.

import { AuthProvider, Registration, Login, PasswordReset } from '@config.one/auth';
import config from './config';

// Create an auth aware axios instance
const axios = createAxios(config);

const App = () => (
  <AuthProvider config={config} tokenAwareAxios={axios}>
    <Registration/>
    <Login/>
    <PasswordReset/>      
  </AuthProvider>
);

It's not necessary for the components to be direct children of the AuthProvider. They can be nested at any depth:

import { AuthProvider, Registration, Login, PasswordReset } from '@config.one/auth';
import config from './config';

const App = () => (
  <AuthProvider config={config}>
    <SomeOtherComponent>
      <AnotherOne>
        <Registration/>
        <Login/>
        <PasswordReset/>  
      </AnotherOne>
    </SomeOtherComponent>  
  </AuthProvider>
);

Registration

import { Registration } from '@config.one/auth';

<Registration
  onSuccess={this.onRegistrationSuccess}
  onFailure={this.onRegistrationFailure}
  onLoginClick={this.onLoginClick}
  showLoginButton={true}
  autoLogin={true}
  onLoginSuccess={this.onLoginSuccess}
  onLoginFailure={this.onLoginFailure}
/>
API

| Name | Type | Default | Description | |-----------------|:---------------:|:--------:|:------------| | onSuccess | function | none | Will be called if the response from the server is successfull (code 2xx). The callback gets 2 arguments: values and response. values contains all the data entered into the form, response is a standard Response object. | onFailure | function | none | Will be called if the response from the server is unsuccessfull (codes 4xx and 5xx). The callback gets 1 argument: values which contains all the data entered into the form. | onLoginClick | function | none | Will be fired by click on the "Login" button on the registration form. | showLoginButton | boolean | true | Show/Hide the "Login" button on the registration form. | autoLogin | boolean | true | Defines whether to automatically sign in after a successful user registration. | onLoginSuccess | function | none | Same as onSuccess, but fires after a successful automatic signing. | onLoginFailure | function | none | Same as onFailure, but fires if automatical signing fails.

Login

import { Login } from '@config.one/auth'

<Login
    onSuccess={this.onLoginSuccess}
    onFailure={this.onLoginFailure}
    onRegistrationClick={this.onRegistrationClick}
    showRegistrationButton={true}
    showForgotPassword={true}
/>
API

| Name | Type | Default | Description | |-----------------|:---------------:|:--------:|:------------| | onSuccess | function | none | Will be called if the response from the server is successfull (code 2xx). The callback gets 2 arguments: values and response. values contains all the data entered into the form, response is a standard Response object. | onFailure | function | none | Will be called if the response from the server is unsuccessfull (codes 4xx and 5xx). The callback gets 1 argument: values which contains all the data entered into the form. | onRegistrationClick | function | none | Will be fired by clickin on the "Registration" button on the registration form. | showRegistrationButton | boolean | true | Show/Hide the "Registration" button on the login form. | showForgotPassword | boolean | true | Show/Hide the "Forgot password" link on the login form.

PhoneVerification

<PhoneVerification
    onSuccess={this.onPhoneVerificationSuccess}
    onFailure={this.onPhoneVerificationFailure}
    onResendSuccess={this.onResendSuccess}
    onResendFailure={this.onResendFailure}
    cooldown={0.5}
    digits={4}
/>
API

| Name | Type | Default | Description | |-----------------|:---------------:|:--------:|:------------| | onVerifySuccess | function | none | Fired on pressing the "Verify" button and if the response from the server is successfull (code 2xx). The callback gets 2 arguments: code and response. code is the OTP entered to the form, response is a standard Response object. | onVerifyFailure | function | none | Fired if the response from the server is unsuccessfull (codes 4xx and 5xx). The callback gets 1 argument, which is the OTP entered to the form. | onResendSuccess | function | none | Fired if the response from the server is successfull (code 2xx). The callback gets 1 argument - a standard Response object. | onResendFailure | boolean | true | Fired if the response from the server is unsuccessfull (codes 4xx and 5xx). The callback gets 1 argument - a standard Response object. | cooldown | int | 1 | Timeout in minutes to be able to resend the SMS. Could be less than 1 (e.g. 0.5) | digits | int | 4 | Number of allowed digits in the code field

ResetPassword & ResetConfirmation

These components should be used in couple. ResetPassword is the form to enter the email to send the resetting link for first time. ResetConfirmation is a confirmation message form with a button, to resend the link.

<ResetPassword
    onSuccess={this.onPasswordResetSuccess}
    onFailure={this.onPasswordResetFailure}
    onLoginClick={this.onLoginClick}
/>

<ResetConfirmation
    onLoginClick={this.onLoginClick}
    onLinkResendSuccess={this.onLinkResendSuccess}
    onLinkResendFailure={this.onLinkResendFailure}
    cooldown={1}
/>
API

| Name | Type | Default | Description | |-----------------|:---------------:|:--------:|:------------| | onSuccess | function | none | Fired on pressing the "Verify" button and if the response from the server is successfull (code 2xx). The callback gets 2 arguments: code and response. code is the OTP entered to the form, response is a standard Response object. | onFailure | function | none | Fired if the response from the server is unsuccessfull (codes 4xx and 5xx). The callback gets 1 argument, which is the OTP entered to the form. | onLoginClick | function | none | Will be fired by clickin on the "Login" button on the registration form. | onLinkResendSuccess | function | none | Fired if the response from the server is successfull (code 2xx). The callback gets 1 argument - a standard Response object. | onLinkResendFailure | boolean | true | Fired if the response from the server is unsuccessfull (codes 4xx and 5xx). The callback gets 1 argument - a standard Response object. | cooldown | int | 5 | Timeout in minutes to be able to resend the link. Could be less than 1 (e.g. 0.5)

AuthChecker

This helper component can be used to decide what to render, depending on the authentication data.

import { Login, AuthChecker } from '@config.one/auth';
import Profile from './Profile';
import UserActivation from './UserActivation';

<AuthChecker>
    {(isLoggedIn, user) => {
        if (isLoggedIn) {
            return user.confirmed ? <Profile user={user}/> : <UserActivation/>;
        } else {
            return <Login />
        }
    }}
</AuthChecker>

License

MIT © Config.one GmbH