Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
hex22a committed Apr 2, 2017
1 parent aacc43c commit dc6c5da
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
lib
dist
.idea
coverage
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ src
yarn.lock
webpack.config.js
.idea
coverage
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,87 @@ React HOC to make usage of JWT extremely fun

## Installation

`yarn add fs-jwt-xhr-hook`

or `npm i --save fs-jwt-xhr-hook` if you are still using npm

## Usage

This package provides a decorator to add isAuthenticated flag and jwtPayload inside component's child context
```javascript
import React, { Component, PropTypes } from 'react';
import jwtContext from 'fs-jwt-react-tools';


@jwtContext
class Main extends Component {

render() {
return (
<div>foo</div>
);
}
}

```

Access data inside child context

```javascript
import React, { PropTypes } from 'react';

const Menu = (props, { isAuthenticated, jwtPayload }) => (
<nav className={ s.header }>
<ul>
<li>
<IndexLink to="/" activeClassName={ s.active }>JWT</IndexLink>
</li>
{isAuthenticated &&
<li>
<Link to="/" activeClassName={ s.active }>{jwtPayload.sub}</Link>
</li>
}
{isAuthenticated &&
<li>
<Link to="/users" activeClassName={ s.active }>Users</Link>
</li>
}
<li>
<Link to="/github" activeClassName={ s.active }>GitHub</Link>
</li>
{!isAuthenticated &&
<li>
<Link to="/sign-in" activeClassName={ s.active }>Sign In</Link>
</li>
}
{!isAuthenticated &&
<li>
<Link to="/sign-up" activeClassName={ s.active }>Sign Up</Link>
</li>
}
{isAuthenticated &&
<li className={ s.pullRight }>
<button onClick={ onLogout }>Logout</button>
</li>
}
</ul>
</nav>
);

Menu.contextTypes = {
isAuthenticated: PropTypes.bool,
jwtPayload: PropTypes.object,
};
```

## Contributing
PR's are welcome 👍

## Credits
Maintained by [Albert Fazullin](http://github.com/AlbertFazullin).

Twitter: [@hex22a](https://twitter.com/hex22a)

Written by [Flatstack](http://www.flatstack.com).

[<img src="http://www.flatstack.com/logo.svg" width="100"/>](http://www.flatstack.com)

0 comments on commit dc6c5da

Please sign in to comment.