react-protected-app

1.0.1 • Public • Published

react-app-protect

NPM

Protect your react application with simple Username and Password prompt (not a replacement for basic auth), which looks like htpassword from Apache server.

Uses base64 to encrypt the password.

Stores the encrypted credentials in the localStorage.

Checks if the stored credentials is valid against generated credentials.

Usage

1. Install

npm install --save react-protected-app
yarn add react-protected-app

2. Wrap Root Component

import React from "react";
import { Router, Route, Routes } from "react-router-dom";
import Home from "./Home";
import Protected from "react-protected-app";

function App() {
  return (
    <Protected>
      <Router>
        <Routes>
          <Route path="/" element={<Home />} />
        </Routes>
      </Router>
    </Protected>
  );
}

export default App;

3. Generate Protected Credentials

Run following command to generate encrypted credentials:

$ protect-credential <username-to-set>
Your credential: <encrypted-username>

$ protect-credential <password-to-set>
Your credential: <encrypted-password>

4. Set Protected Credentials

Set following environment variables with your protected credentials:

PROTECTED_USERNAME="<encrypted-username>"
PROTECTED_PASSWORD="<encrypted-password>"

5. Start your application server

Logo

License

MIT © MuhammadZeeshanYousaf

Package Sidebar

Install

npm i react-protected-app

Weekly Downloads

15

Version

1.0.1

License

MIT

Unpacked Size

20.2 kB

Total Files

7

Last publish

Collaborators

  • zeeshanyousaf