How it works...

Adding sign up, sign in, and sign out to a single-page app is very straightforward. We include some additional libraries, initialize them with the proper configurations, and decorate the existing code. In this recipe, we make these changes to our simple example React application. AWS provides the amazon-cognito-auth-js library to simplify this task and we wrap it in some React components in src/authenticate folder. First, we initialize the CognitoSecurity component in the src/App.js. Next, we set up SecureRoute for the Home component that will redirect to the Cognito hosted UI if the user is not authenticated. The ImpicitCallback component will handle the redirect after the user logs in. Finally, we add the withAuth decorator ...

Get JavaScript Cloud Native Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.