Skip to content

Commit

Permalink
add federation option to withAuthencitaion hoc
Browse files Browse the repository at this point in the history
  • Loading branch information
powerful23 committed Dec 5, 2017
1 parent 664ffc8 commit ef841e1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
15 changes: 14 additions & 1 deletion media/authentication_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,27 @@ export default withAuthenticator(App);

Now your app is guarded by complete Auth flow. Only signed in user can access the app.

#### Federated Identity

You can enable federated Identity login by specifying federated option.

```js
const federated = {
google_client_id: '',
facebook_app_id: ''
};

export default withAuthenticator(App, { federated });
```

#### Sign Out Button

The default `withAuthenticator` renders just the App component after a user is signed in, preventing interference with your app. Then question comes, how does the user sign out?

To expose this, set the second parameter to true, which means `includeGreetings = true`. It will put a greeting row on top of your app.

```js
export default withAuthenticator(App, true);
export default withAuthenticator(App, { includeGreetings: true });
```

### 3. Authenticator Component
Expand Down
7 changes: 3 additions & 4 deletions packages/aws-amplify-react/dist/Auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
* and limitations under the License.
*/

function withAuthenticator(Comp) {
var includeGreetings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

function withAuthenticator(Comp, options) {
return function (_Component) {
_inherits(_class, _Component);

Expand Down Expand Up @@ -239,7 +237,7 @@ function withAuthenticator(Comp) {
return _react2['default'].createElement(
'div',
null,
includeGreetings ? _react2['default'].createElement(_Greetings2['default'], {
options && options.includeGreetings ? _react2['default'].createElement(_Greetings2['default'], {
authState: authState,
authData: authData,
onStateChange: this.handleAuthStateChange
Expand All @@ -253,6 +251,7 @@ function withAuthenticator(Comp) {
}

return _react2['default'].createElement(_Authenticator2['default'], _extends({}, this.props, {
federated: options && options.federated,
onStateChange: this.handleAuthStateChange
}));
}
Expand Down
5 changes: 3 additions & 2 deletions packages/aws-amplify-react/src/Auth/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export * from './Provider';

import Greetings from './Greetings';

export function withAuthenticator(Comp, includeGreetings=false) {
export function withAuthenticator(Comp, options) {
return class extends Component {
constructor(props) {
super(props);
Expand All @@ -54,7 +54,7 @@ export function withAuthenticator(Comp, includeGreetings=false) {
return (
<div>
{
includeGreetings?
options && options.includeGreetings?
<Greetings
authState={authState}
authData={authData}
Expand All @@ -74,6 +74,7 @@ export function withAuthenticator(Comp, includeGreetings=false) {

return <Authenticator
{...this.props}
federated={options && options.federated}
onStateChange={this.handleAuthStateChange}
/>
}
Expand Down

0 comments on commit ef841e1

Please sign in to comment.