1.8.7 • Published 2 years ago

@xterr/react-authentication v1.8.7

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

React Authentication

Universal Authentication with support for simple JWT and OAuth 2.0 authentication

Installation

npm install --save @xterr/react-authentication

or:

yarn add @xterr/react-authentication

Getting Started

Configure the library wrapping your application in AuthProvider:

import React from 'react';
import { AuthProvider } from '@xterr/react-authentication';
import App from './App';

const App = () => (
  <AuthProvider>
    <App/>
  </AuthProvider>
)

Protect a route

Example of a component that can protect other components and redirect the user to a login page if the user is not authenticated:

import React from 'react';
import { useAuth } from '@xterr/react-authentication';
import { Navigate } from 'react-router';

const ProtectedRoute = ({redirectTo, children}) => {
  const {authState: {isAuthenticated}} = useAuth();
  return (isAuthenticated ? React.Children.only(children) : <Navigate to={redirectTo} replace/>);
};
1.8.7

2 years ago

1.8.6

2 years ago

1.8.5

2 years ago

1.8.4

2 years ago

1.8.3

2 years ago

1.8.2

2 years ago

1.8.1

2 years ago

1.8.0

2 years ago

1.7.0

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.4.0

2 years ago

1.0.0

2 years ago