Skip to content

Commit

Permalink
feat(project): Add initial project files 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
joelseq committed Mar 29, 2018
0 parents commit 5cffc2e
Show file tree
Hide file tree
Showing 15 changed files with 21,833 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
["env", {
"modules": false
}],
"stage-0",
"react"
],
"plugins": [
"external-helpers"
]
}
45 changes: 45 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: 2
jobs:
test:
docker:
- image: circleci/node:8
steps:
- checkout

# Download and restore cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: yarn install

- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}

# run tests!
- run: yarn test

release:
docker:
- image: circleci/node:8
steps:
- checkout
- run: yarn install
# Build project
- run: yarn build
# Release new version
- run: npx semantic-release

workflows:
version: 2
test_and_release:
# Run the test job first, then release only when the test job is successful
jobs:
- test
- release:
requires:
- test
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{js,css,scss,html}]
charset = utf-8
indent_style = space
indent_size = 2
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "react-app"
}
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
node_modules

# builds
build
dist

# code coverage reports
coverage

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<h1 align="center">React-Router-Auth</h1>

> A utility library for React Router v4 for managing authentication based routing
[![NPM Version][npm-badge]][npm]
[![Build Status][build-badge]][build]
[![Code Coverage][coverage-badge]][coverage]

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.

## Install

```bash
npm install --save react-router-auth

OR

yarn add react-router-auth
```

## Usage

### AuthRoute

Use this component if you have a route that requires the user to be authenticated for them to be able to access it.

e.g. to access user profile page

```jsx
import React, { Component } from 'react'
import { AuthRoute } from 'react-router-auth'
import UserProfile from './UserProfile'

class Example extends Component {
render () {
return (
<AuthRoute path="/profile" component={UserProfile} redirectTo="/login" authenticated={this.props.authenticated} />
)
}
}
```

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.

#### Props

| Name | Type | Description |
|---------------|-----------------|--------------------------------------------------------|
| authenticated | boolean | Whether the user is authenticated or not |
| redirectTo | string | The route to redirect the user to if not authenticated |
| component | React Component | The component that requires authentication |

### UnauthRoute

Use this component if you have a route that a user should only be able to access if they aren't already authenticated.

e.g. to access the login / signup pages

```jsx
import React, { Component } from 'react'
import { UnauthRoute } from 'react-router-auth'
import Login from './Login'

class Example extends Component {
render () {
return (
<UnauthRoute path="/login" component={Login} redirectTo="/feed" authenticated={this.props.authenticated} />
)
}
}
```

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.

#### Props

| Name | Type | Description |
|---------------|-----------------|----------------------------------------------------|
| authenticated | boolean | Whether the user is authenticated or not |
| redirectTo | string | The route to redirect the user to if authenticated |
| component | React Component | The component that requires authentication |


## License

MIT © [joelseq](https://twitter.com/joelseq03)

[build-badge]: https://img.shields.io/circleci/project/github/joelseq/react-router-auth.svg?style=flat-square
[build]: https://circleci.com/gh/joelseq/react-router-auth
[npm-badge]: https://img.shields.io/npm/v/react-router-auth.svg?style=flat-square
[npm]: https://www.npmjs.com/package/react-router-auth
[coverage-badge]: https://img.shields.io/codecov/c/github/joelseq/react-router-auth.svg?style=flat-square
[coverage]: https://codecov.io/github/joelseq/react-router-auth
Loading

0 comments on commit 5cffc2e

Please sign in to comment.