react-auth-component

3.0.19 • Public • Published

react-auth-component

react-auth-component

NPM JavaScript Style Guide

Install

npm install --save react-auth-component

Usage

This is a simple manager of login & registration with JWT json web token, is good to use if you want to create a login very fast just to start your application.

IMPORTANT!: In the Example behind the api rest the you are calling expect a Json with field called 'jwt'. If you have a different name put in : tokenName="yournameTokenJson" EXAMPLE of json that you can receive:

{ "yournameTokenJson": "eyJhbGcinometokencasualJH6omU", "id": 12, }

if as a response it has a String it will be showd as message in red

import React, { Component } from 'react'
import { Route, Link, Routes } from 'react-router-dom'; 
import Home from '../page/home';
import About from '../page/notFound';
import { Auth } from 'react-auth-component'
import 'react-auth-component/dist/index.css'

class Example extends Component {
  render() {
    <>
      <nav>
        <Link to="/home">Home</Link>
        <Link to="/about">About</Link>
        <Link to="/">Login</Link>
      </nav>
      <Routes>
        <Route path="/home" element={<Home />} />
        <Route path="/about" element={<About />} />
        <Route
          exact
          path="/"
          element={
            <Auth
              PageAuthenticated="home"
              urlRegister="http://example.com/api/auth/register"
              urlLogin="http://example.com/api/auth/login"
              tokenServerName="jwt"
            />
          }
        />
      </Routes>
    </>
  }
}

const App = () => {
  return (
    <Router>
      <Example />
    </Router>
  );
};

License

MIT © ddaniel9

Readme

Keywords

none

Package Sidebar

Install

npm i react-auth-component

Weekly Downloads

75

Version

3.0.19

License

MIT

Unpacked Size

648 kB

Total Files

7

Last publish

Collaborators

  • da-npm