React Boilerplate extended swith login/register flow built with React & Redux Saga. react-boilerplate-auth.herokuapp.com
Authentication happens in app/auth/index.js
, using fakeRequest.js
and fakeServer.js
. fakeRequest
is a fake XMLHttpRequest
wrapper. fakeServer
responds to the fake HTTP requests and pretends to be a real server, storing the current users in local storage with the passwords encrypted using bcrypt
.
react-boilerplate-auth.herokuapp.com
Username: test
Password: password
Available routes:
/home
(only accessible when logged in)/login
/register
- Clone this repo using
git clone [email protected]:andreasasprou/react-boilerplate-auth.git
- Run
npm run setup
to install dependencies and clean the git repo. - At this point you can
run npm start
to see the example app athttp://localhost:3000
.
Documentation about the extensive features of React Boilerplate and general use of this boilerplate can be found here.
I highly reccommend you read this before attempting to create a project using this boilerplate.
All global reducers, sagas and actions responsible for authentication are defined under /App
. Examples of logging in, logging out and registering new users are described in the containers LoginPage, HomePage and RegisterPage respectively.
To create a secure route (one which cannot be accessed without logging in), ensure that when creating a new route in app/routes.js
, you set the onEnter
property to (nextState, replace) => checkAuth(store, nextState, replace)
.
E.g.
...
}, {
path: 'home',
name: 'homePage',
onEnter: (nextState, replace) => checkAuth(store, nextState, replace),
getComponent(location, cb) {
import
('containers/HomePage')
.then(loadModule(cb))
.catch(errorLoading);
},
}, {
...