1.1.7 • Published 2 years ago

local-storage-auth v1.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

local-storage-auth

This is an npm library for managing authentication for a website using localStorage and routing.

CS 3162 - Professional Responsibility in Computer Science and Software Engineering

Install

npm install local-storage-auth

# or

yarn add local-storage-auth

Usage

import React from 'react';
import { setAuth, checkAuth } from 'local-storage-auth';

// checkAuth() without redirection
function TestPage() {
  checkAuth();
  return (
    <h2>Test Page</h2>
  )
}

// checkAuth() with redirection
function Error() {
  checkAuth("/home"); 
  return (
    <h2>404 Page</h2>
  )
}

// setAuth()
function Login() {
  return (
    <div>
  {/* If person enters Correct Login Information */} 
      <button onClick={() => setAuth(true)}>Login Correct</button>
      
  {/* If person enters Wrong Login Information */}
      <button onClick={() => setAuth(false)}>Login Incorrect</button>
    </div>
  )
}

Props

MethodTypeDefaultDescriptionExamples
checkAuth()string or nullnullcheckAuth() can either have no props or accepts the page you want to redirect to as a string.checkAuth() or checkAuth("/home")
setAuth()booleanfalsesetAuth() accepts a boolean depending on if you want the user to be logged in or notsetAuth(true)

Local Development

# no build scripts required since the project has no dependencies

Example

An example website has been created and deployed if you want to see the package being used in action. Happy Coding!

Contributing

If you like this project and want to contribute, create a fork and make a pull request to the main branch. Check out some issues you can contribute to.

You can also contribute by sending me some money so I have more motivation to work on this project. My Venmo is @aniumarji05

License

MIT

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago