1.0.21 • Published 4 years ago

mio-library-autenticacao v1.0.21

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

mio-library-autenticacao

Componente React para login

NPM JavaScript Style Guide

Instalação

//npm
npm install --save mio-library-autenticacao

//yarn
yarn add mio-library-autenticacao

Como utilizar

Você deve definir os seguintes parâmetros de configuração no arquivo .env

REACT_APP_ID=app-id-example
REACT_APP_MIO_AUTH_API_URL=http://urlofauthentication.com:3000
REACT_APP_MIO_AUTH_TOKEN=persist:@mio-template:jwt-token
import React, { Component } from "react";

import { Autenticacao } from "mio-library-autenticacao";

const Example = props => {
  return (
    <Autenticacao
      beforeSubmit={() => {
        // do something before submitting the login form
      }}
      afterSubmit={result => {
        /*
         * Do something after submitting the login form.
         * result is a json that can contain three attributes
         * {
         *    status: <boolean>
         *    message: <string> in case status is false message is undefined
         *    error: <string> in case status is true error is undefined
         * }
         */

        /*
         * Example, you can redirect page if login is succefully
         */
        if (result.status) {
          props.history.push("/home");
        }
      }}
    />
  );
};

export default Example;

Api

<Autenticacao />

The component accepts the following props:

NameTypeDescription
onSubmitfunctionSobrescreva está função caso queira utilizar seu próprio método de autenticação. (e, email, password) => { //faça algo }
beforeSubmitfunctionFunção callback que é disparada antes do envio de formulário de login.
afterSubmitfunctionFunção callback que é disparada antes do envio de formulário de login.

Helpers

mio-library-autenticacao provides auxiliary methods

NameReturnDescription
isAuthenticatedbooleanretorna se o usuário está autenticado ou não
getTokenstringA token jwt salca no local storage
getDatajsonextrai os dados da token jwt
logoutvoidfaz o logout do usuário

License

MIT © raphaelbsr

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago