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-router-authenticator

v1.1.1

Published

Biblioteca para autenticação e controle de rotas

Downloads

12

Readme

React Router Authenticator

Esta biblioteca tem como finalidade auxiliar os desenvolvedores a terem uma melhor forma de trabalhar com rotas privadas e públicas.

Antes de começar

Esta biblioteca trabalha em conjunto com a React Router, utilizando certas funcionalidades que não teriam necessidade de serem reescritas. Sendo assim leiam, com atenção cada seção desse documento.

Instalação

npm install react-router-authenticator

Modo de uso

import { BrowserRouter, Switch } from "react-router-dom";
import { Authenticator, AuthRoute } from 'react-router-authenticator';

export default () => {
		
  return (
    <BrowserRouter>
      <Switch>
        <Authenticator onValidator={() => true} validRedirect="/dashboard" invalidRedirect="/login">
          <AuthRoute exact path="/" component={Home} restricted />
          <AuthRoute exact path="/login" component={Login} restricted />
          <AuthRoute exact path="/dashboard" component={Dashboard} isPrivate />
          <AuthRoute exact path="/route-one" component={Component1} isPrivate />
          <AuthRoute exact path="/route-two" component={Component2} isPrivate />
          <AuthRoute exact path="/route-three" component={Component3} isPrivate />
          <AuthRoute exact path="/route-four" component={Component4} isPrivate />
          <AuthRoute exact path="/route-five" component={Component5} isPrivate />
          <AuthRoute exact path="/route-six" component={Component6} isPrivate />
          <AuthRoute exact path="/route-seven">
            <Component7 />
          </AuthRoute>
          <AuthRoute exact path="/route-eight" isPrivate>
            <Component8 />
          </AuthRoute>
          <AuthRoute exact path="/route-nine" isPrivate>
            <Component9 />
          </AuthRoute>
        </Authenticator>
      </Switch>
    </BrowserRouter>
  );
};

Componentes

Authenticator (Obrigátorio)

Este componente é responsável pelo contexto funcional da biblioteca, ele possui apenas 3 (três) propriedades básicas para o seu bom uso. Sendo elas onValidator, validRedirect e invalidRedirect, exemplo:

<Authenticator onValidator={() => true} validRedirect="/dashboard" invalidRedirect="/login">
  <AuthRoute exact path="/" component={Home} />
  <AuthRoute exact path="/login" component={Login} restricted />
  <AuthRoute exact path="/dashboard" component={Dashboard} isPrivate />
</Authenticator>

Propriedades

| Propriedade | Tipo | Descrição | Padrão | | ------ | ------ | ------ | ------ | | onValidator | Function | Callback responsável pela validação das rotas privadas, para que uma rota privada seja acessada, é necessário que o callback retorne true | Falso | | validRedirect | String | Rota usada para redirecionar caso tente acessar uma rota com a propriedade restricted e que não seja privada, caso o callback de onValidator retorne true | Vázio | | invalidRedirect | String | Rota usada para redirecionar caso tente acessar uma rota privada, caso o callback de onValidator retorne false | Vázio |

AuthRoute (Obrigátorio)

Este componente espelha todas as propriedades do componente Route da biblioteca React Router, porém, algumas novas funcionalidades são adicionadas a ele. Sendo elas isPrivate e restricted, exemplo:

<AuthRoute exact path="/" component={Home} />
<AuthRoute exact path="/login" component={Login} restricted />
<AuthRoute exact path="/dashboard" component={Dashboard} isPrivate />

Propriedades

| Propriedade | Tipo | Descrição | Padrão | | ------ | ------ | ------ | ------ | | isPrivate | Boolean | Valor booleano que determina se é uma rota privada | Falso | | restricted | Boolean | Valor booleano que determina se uma rota pública se torna restrita após o uso de um callback definido na propriedade onValidator do componente Authenticator | Falso | | as | Element | Este atributo é exclusivo para trabalhar em conjunto com o componente MapRoute da biblioteca React Router Mapping | Vázio |