Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@auth-kit/react-router

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@auth-kit/react-router

React Router Support for React-auth-kit

  • 3.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1K
increased by59.51%
Maintainers
1
Weekly downloads
 
Created
Source

@auth-kit/react-router

Test Suites Test Suites

https://authkit.arkadip.dev 🚀

🔑 This library is a part of the `react-auth-kit` ecosystem. 🔑

This library contains useful functions to manage private routes using react-router* or react-router-dom.

Usage

AuthOutlet

AuthOutlet provides an easy solution using react-router or react-router-dom to manage private-route.

Routes inside the AuthOutlet will stay protected and only properly authenticated users can access the route.

If the user is not authenticated then the user will be redirected to the fallbackPath.

Example
import AuthOutlet from '@auth-kit/react-router/AuthOutlet';

function App() {
 return (
   <Router>
     <Routes>
       <Route element={<AuthOutlet fallbackPath='/login' />}>
         <Route path='/' element={<Users/>} />
         <Route path='/products' element={<Products/>} />
       </Route>
       <Route path='/login' element={<Login/>}/>
     </Routes>
   </Router>
 );
}

RequireAuth

RequireAuth provides a per route base private route solution to implement a private route solution.

Component inside the RequireAuth will stay protected and only properly authenticated users can access the route.

If the user is not authenticated then the user will be redirected to the fallbackPath.

Example
import RequireAuth from '@auth-kit/react-router/RequireAuth';

const RoutesComponent = () => {
 return (
   <BrowserRouter>
     <Routes>
       <Route path={'/'} element={<Home/>}/>
       <Route path={'/login' } element={<Login/>}/>
       <Route path={'/secure'} element={
         <RequireAuth fallbackPath={'/login'}>
           <SecureComponent/>
         </RequireAuth>
       }/>
     </Routes>
   </BrowserRouter>
 )
}

Reference

Reference


— 🔑 —

React Auth Kit is MIT License code

Keywords

FAQs

Package last updated on 20 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc