Skip to content

TypedBootstrap/authentication-in-react

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Authentication in React

App preview

Introduction

This proof-of-concept has been heavily inspired by a blog post I read by Kent C. Dodds (which I encourage you to go and read also). What this application does is checks to see if the current user is authenticated. If they are not, then they are restricted access to routes specifically for authenticated users.

I have achieved this by wrapping the <App /> component in a couple of react providers. Firstly the <AuthProvider /> is responsible for bootstrapping the app data. Then secondly the <UserProvider /> is responsible for keeping the user data up to date in memory.

The <App/ > component will render the <UnauthenticatedApp /> component until the current users data is retrieved. Once that data has been fulfilled it is determined that the user is logged in and the <AuthenticatedApp /> component will be rendered instead. It will be literally impossible to render one side of the app or the other if there is no user.

License

Licensed under MIT. Totally free for private or commercial projects.

Installation

It is advised that you download this repo as opposed to cloning. This will avoid any accidental project commits to this repository.

Demo

A working demo of this application can be found here. Use the credentials admin and password to authentcaite with the test user.

Credits