Skip to content

Commit 5cffc2e

Browse files
committed
feat(project): Add initial project files 🎉
0 parents  commit 5cffc2e

File tree

15 files changed

+21833
-0
lines changed

15 files changed

+21833
-0
lines changed

.babelrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"presets": [
3+
["env", {
4+
"modules": false
5+
}],
6+
"stage-0",
7+
"react"
8+
],
9+
"plugins": [
10+
"external-helpers"
11+
]
12+
}

.circleci/config.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
version: 2
2+
jobs:
3+
test:
4+
docker:
5+
- image: circleci/node:8
6+
steps:
7+
- checkout
8+
9+
# Download and restore cache dependencies
10+
- restore_cache:
11+
keys:
12+
- v1-dependencies-{{ checksum "package.json" }}
13+
# fallback to using the latest cache if no exact match is found
14+
- v1-dependencies-
15+
16+
- run: yarn install
17+
18+
- save_cache:
19+
paths:
20+
- node_modules
21+
key: v1-dependencies-{{ checksum "package.json" }}
22+
23+
# run tests!
24+
- run: yarn test
25+
26+
release:
27+
docker:
28+
- image: circleci/node:8
29+
steps:
30+
- checkout
31+
- run: yarn install
32+
# Build project
33+
- run: yarn build
34+
# Release new version
35+
- run: npx semantic-release
36+
37+
workflows:
38+
version: 2
39+
test_and_release:
40+
# Run the test job first, then release only when the test job is successful
41+
jobs:
42+
- test
43+
- release:
44+
requires:
45+
- test

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
7+
[*.{js,css,scss,html}]
8+
charset = utf-8
9+
indent_style = space
10+
indent_size = 2

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "react-app"
3+
}

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
# See https://help.github.com/ignore-files/ for more about ignoring files.
3+
4+
# dependencies
5+
node_modules
6+
7+
# builds
8+
build
9+
dist
10+
11+
# code coverage reports
12+
coverage
13+
14+
# misc
15+
.DS_Store
16+
.env
17+
.env.local
18+
.env.development.local
19+
.env.test.local
20+
.env.production.local
21+
22+
npm-debug.log*
23+
yarn-debug.log*
24+
yarn-error.log*

README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<h1 align="center">React-Router-Auth</h1>
2+
3+
> A utility library for React Router v4 for managing authentication based routing
4+
5+
[![NPM Version][npm-badge]][npm]
6+
[![Build Status][build-badge]][build]
7+
[![Code Coverage][coverage-badge]][coverage]
8+
9+
This library is based off of the code from the [React Router v4 Docs](https://reacttraining.com/react-router/web/example/auth-workflow). The purpose of this library is to make it easy to handle redirecting users for routes that require the user to either be authenticated or unauthenticated.
10+
11+
## Install
12+
13+
```bash
14+
npm install --save react-router-auth
15+
16+
OR
17+
18+
yarn add react-router-auth
19+
```
20+
21+
## Usage
22+
23+
### AuthRoute
24+
25+
Use this component if you have a route that requires the user to be authenticated for them to be able to access it.
26+
27+
e.g. to access user profile page
28+
29+
```jsx
30+
import React, { Component } from 'react'
31+
import { AuthRoute } from 'react-router-auth'
32+
import UserProfile from './UserProfile'
33+
34+
class Example extends Component {
35+
render () {
36+
return (
37+
<AuthRoute path="/profile" component={UserProfile} redirectTo="/login" authenticated={this.props.authenticated} />
38+
)
39+
}
40+
}
41+
```
42+
43+
In this example, if the user is authenticated while they try to access the `/profile` route, then the `UserProfile` component will be rendered. If the user is not authenticated then it will redirect them to the `/login` route.
44+
45+
#### Props
46+
47+
| Name | Type | Description |
48+
|---------------|-----------------|--------------------------------------------------------|
49+
| authenticated | boolean | Whether the user is authenticated or not |
50+
| redirectTo | string | The route to redirect the user to if not authenticated |
51+
| component | React Component | The component that requires authentication |
52+
53+
### UnauthRoute
54+
55+
Use this component if you have a route that a user should only be able to access if they aren't already authenticated.
56+
57+
e.g. to access the login / signup pages
58+
59+
```jsx
60+
import React, { Component } from 'react'
61+
import { UnauthRoute } from 'react-router-auth'
62+
import Login from './Login'
63+
64+
class Example extends Component {
65+
render () {
66+
return (
67+
<UnauthRoute path="/login" component={Login} redirectTo="/feed" authenticated={this.props.authenticated} />
68+
)
69+
}
70+
}
71+
```
72+
73+
In this example, if the user is authenticated while they try to access the `login` route, they will be redirected to the `/feed` route. If the user is not authenticated, then the `Login` component will be rendered.
74+
75+
#### Props
76+
77+
| Name | Type | Description |
78+
|---------------|-----------------|----------------------------------------------------|
79+
| authenticated | boolean | Whether the user is authenticated or not |
80+
| redirectTo | string | The route to redirect the user to if authenticated |
81+
| component | React Component | The component that requires authentication |
82+
83+
84+
## License
85+
86+
MIT © [joelseq](https://twitter.com/joelseq03)
87+
88+
[build-badge]: https://img.shields.io/circleci/project/github/joelseq/react-router-auth.svg?style=flat-square
89+
[build]: https://circleci.com/gh/joelseq/react-router-auth
90+
[npm-badge]: https://img.shields.io/npm/v/react-router-auth.svg?style=flat-square
91+
[npm]: https://www.npmjs.com/package/react-router-auth
92+
[coverage-badge]: https://img.shields.io/codecov/c/github/joelseq/react-router-auth.svg?style=flat-square
93+
[coverage]: https://codecov.io/github/joelseq/react-router-auth

0 commit comments

Comments
 (0)