<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Fullstack with React-Native, AWS Serverless and Google oAuth2 Sign-In - Medium]]></title>
        <description><![CDATA[A step-by-step guide to build a full-stack application using AWS Serverless and React-native. - Medium]]></description>
        <link>https://medium.com/fullstack-with-react-native-aws-serverless-and?source=rss----a22852ba80ba---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Fullstack with React-Native, AWS Serverless and Google oAuth2 Sign-In - Medium</title>
            <link>https://medium.com/fullstack-with-react-native-aws-serverless-and?source=rss----a22852ba80ba---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 08:19:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/fullstack-with-react-native-aws-serverless-and" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Home screen with data fetched from database]]></title>
            <link>https://medium.com/fullstack-with-react-native-aws-serverless-and/home-screen-with-data-fetched-from-database-c2c3759effd9?source=rss----a22852ba80ba---4</link>
            <guid isPermaLink="false">https://medium.com/p/c2c3759effd9</guid>
            <category><![CDATA[redux-thunk]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Bharat Tiwari]]></dc:creator>
            <pubDate>Wed, 06 Feb 2019 16:02:37 GMT</pubDate>
            <atom:updated>2019-02-06T16:02:35.860Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part ɪɪɪ: Connect UI to API │Story 04 : Update Home screen to connect to redux, fetch data from db; add View, Edit and Delete word functionality</h4><figure><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and"><img alt="" src="https://cdn-images-1.medium.com/proxy/1*oMNRVTNNfDMCgVOc0LVhhA.png" /></a></figure><p>GIT :<em> </em><a href="https://github.com/jsified-brains/noteWordy-UI">Repo</a><em>| </em><a href="https://github.com/jsified-brains/noteWordy-UI/tree/home-screen-connected">Feature/Story branch</a><em> | </em><a href="https://github.com/jsified-brains/noteWordy-UI/pull/13">PR</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iF14E38y5SynZrUYlOMqBQ.png" /></figure><p>In the <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/connect-react-native-to-serverless-api-aws-sign-in-with-amplify-sdk-2dc4420fa851">previous post</a>, we added Amplify’s <strong>Auth.federatedSignIn</strong> method to our <strong>UserSignIn</strong> component to connect our app to AWS Cognito Identity pool and get authenticated from AWS. With this, we can now access the authorized AWS resources, like we able to make queries to serverless API.</p><p>In this post, we would update our Home screen to connect it with API/database via redux, replace the static list of words that we had so far on the screen with a dynamic list of words fetched from database and add View, Edit and delete words features.</p><p>We have <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/add-redux-store-actions-and-reducers-for-words-data-427db25fa05f">already defined the redux</a> store, actions, reducers for all CRUD operations with word data in this previous post.</p><p>To connect Home screen with redux:<br>📝 Create a file HomeConnected.js under src/screens/Home folder 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38607f8bfc8aef39f83cae82bd61203f/href">https://medium.com/media/38607f8bfc8aef39f83cae82bd61203f/href</a></iframe><p>Update src/screens/Home/HomeScreen.js 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f310de3b37fce17b6d965a4cf43273d8/href">https://medium.com/media/f310de3b37fce17b6d965a4cf43273d8/href</a></iframe><p>With above updates to Home screen component, we removed the static list of words and replaced it with list of words in user’s vocab collection that we fetch from database, below is a summary of changes we made:</p><blockquote><em>– In </em><em>componentDidMount method, we trigger </em><em>fetchUserVocabWords action to fetch the user’s words collection from database.</em></blockquote><blockquote><em>– We also subscribed to react navigator’s </em><em>didFocus event (this event is triggered by the react-navigation whenever this component would be activated and brought up on the device screen). In this event as well we trigger </em><em>fetchUserVocabWords action to get the most updated list of words.</em></blockquote><blockquote><em>– In </em><em>render method, we are rendering </em><em>AppHeader, the screen’s main contents, a fab button to allow us to go to </em><em>AddEditWord screen and also a Delete confirmation/alert box that will be shown whenever user would press delete button on any word in the list.</em></blockquote><blockquote><em>– </em><em>renderContent method would render a loading/activity indicator if the app’s is in the state of fetching word from database and once the words are fetched, it would render list of the words.</em></blockquote><blockquote><em>– other helper methods to render other things like Fab button or delete confirmation box and callback functions for various events on screen.</em></blockquote><blockquote><em>– Notice the method </em>onListItemPress<em>:</em> <em>In this method, after triggering the redux action </em>selectWordToView<em>, we navigate the user to ‘Word’ screen. This screen component is not ready yet, we’ll add it next.</em></blockquote><p>Update src/screens/index.js to export HomeConnected component for Home screen👇</p><pre><strong>export { default as HomeScreen } from &#39;./Home/HomeConnected&#39;;</strong><br>export { default as SignInScreen } from &#39;./SignIn/SignIn&#39;;<br>export { default as AddEditWordScreen } from &#39;./AddEditWord/AddEditWordConnected&#39;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><h3>Screen to view a selected word</h3><p>Next, we’ll add a screen to show the selected word details like its meaning, example and comments. From Home screen, when user taps on a word in his/her vocabulary, this screen would be shown.</p><p>📂 Create a folder Word under src/screens <br>📝 Create a file Word.js under src/screens/Word folder 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff76aace7617c6c10b442efe9f4de2d7/href">https://medium.com/media/ff76aace7617c6c10b442efe9f4de2d7/href</a></iframe><p>📝 Create a file WordConnected.js under src/screens/Word folder 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d4e17a353bc236e825a7ffa00c3e078/href">https://medium.com/media/0d4e17a353bc236e825a7ffa00c3e078/href</a></iframe><p>📝 Create styles.js under src/screens/Word folder 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f11b6675b36fc74f47bc989a7a867cc8/href">https://medium.com/media/f11b6675b36fc74f47bc989a7a867cc8/href</a></iframe><p>Update src/screens/index.js to export WordConnected component for Home screen👇</p><pre>export { default as HomeScreen } from &#39;./Home/HomeConnected&#39;;<br>export { default as SignInScreen } from &#39;./SignIn/SignIn&#39;;<br>export { default as AddEditWordScreen } from &#39;./AddEditWord/AddEditWordConnected&#39;;<br><strong>export { default as WordScreen } from &#39;./Word/WordConnected&#39;;</strong></pre><h4>Add WordScreen to the app’s stack navigator,</h4><p>Update src/routes/AppStackNavigator.js as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/208aedcdb5cc9e066635ec34ea9da150/href">https://medium.com/media/208aedcdb5cc9e066635ec34ea9da150/href</a></iframe><p>👆Lint # 9 we added Word screen to the app’s stack navigator.</p><h3>NoteWordy App with all features:</h3><p>Finally we have everything implemented to Create, Read/View, Update/Edit and Delete word data. Lets see if everything is working as expected</p><p>Reload or rerun the app on iOS:</p><pre>$ react-native run-ios  </pre><p>and on Android:</p><pre>$ react-native run-android</pre><ol><li>Read/View Words</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*4rilZQBuwFzkZgqN-YgmPg.gif" /></figure><p>2. Add a word</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*TK7EOTtlEsksQ2oXRubxRA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/76/1*r8472fmGoCvSOgZXnLsIgA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*VAALV_d2fWY0XVfvxAi9qQ.gif" /></figure><p>3. Edit a word</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*oVW2RSku6WL-ccoC7HrJug.gif" /></figure><p>4. Delete a word: 👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*V2DlZbCXRn_D1Lqqy-vFXw.gif" /></figure><p>Yay!!!! Congratulations!! Our app is ready to go live.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxT8qBkXehPSstbhfWM%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FxT8qBkXehPSstbhfWM%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FxT8qBkXehPSstbhfWM%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="243" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ca0bf65a8f6b0d798c4aab730de11e1/href">https://medium.com/media/2ca0bf65a8f6b0d798c4aab730de11e1/href</a></iframe><p>That concludes this 3-part series:</p><p>In Part-I, we built and deployed serverless API to AWS.</p><p>In Part-II, we developed our react-native application and added Google Sing-in to it for user authentication.</p><p>And finally in Part-III, we connected our react-native app to AWS using the AWS Cognito Identity pool to authenticate and authorize our app’s requests to the serverless API deployed in AWS.</p><p>As <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/fullstack-with-react-native-aws-serverless-and-google-sign-in-b6f263b76c9f/#aa04">stated earlier</a>, the purpose of this series was to demonstrate how to develop a full stack application using Google Sign-in, React-Native, AWS Authentication and AWS Serverless API/lambdas and how these different technologies connect together. We didn’t cover unit testing and making apps production ready to publish to Apple or android stores. Stay tuned for Push Notifications feature.</p><p>Thank you!!! Hope you enjoyed the series and would found it helpful.<strong> </strong>Feedback, comments and suggestions are welcome.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/credits-references-and-useful-resources-8b2b2350491d">Credits, references and useful resources</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/connect-react-native-to-serverless-api-aws-sign-in-with-amplify-sdk-2dc4420fa851"><strong>← </strong></a><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/connect-react-native-to-serverless-api-aws-sign-in-with-amplify-sdk-2dc4420fa851"><strong>Prev:AWS Signin</strong></a><strong> </strong>┈<a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">🏠</a>┈<strong>Next:Push Notifications(stay tuned)→</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2c3759effd9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/home-screen-with-data-fetched-from-database-c2c3759effd9">Home screen with data fetched from database</a> was originally published in <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">Fullstack with React-Native, AWS Serverless and Google oAuth2 Sign-In</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Credits, references and useful resources]]></title>
            <link>https://medium.com/fullstack-with-react-native-aws-serverless-and/credits-references-and-useful-resources-8b2b2350491d?source=rss----a22852ba80ba---4</link>
            <guid isPermaLink="false">https://medium.com/p/8b2b2350491d</guid>
            <category><![CDATA[aws-cognito]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Bharat Tiwari]]></dc:creator>
            <pubDate>Wed, 06 Feb 2019 15:28:52 GMT</pubDate>
            <atom:updated>2019-02-06T16:28:24.476Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and"><img alt="" src="https://cdn-images-1.medium.com/proxy/1*oMNRVTNNfDMCgVOc0LVhhA.png" /></a></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lJ9hK6gZnmUXP-ibwP2TOw.jpeg" /><figcaption>Photo credits: <a href="https://pixabay.com/en/wood-chalkboard-wooden-old-antique-3190203/">Pixabay</a></figcaption></figure><h3>Credits</h3><p><a href="https://serverless-stack.com/">Serverless Stack</a></p><p>A big thanks to the creators of <a href="https://serverless-stack.com/">Learn to Build Full-Stack Apps with Serverless and React on AWS</a>. AWS Cognito User Pools vs Identity pool and the various terminologies involved were all very confusing to me. This guild helped me to get my AWS IAM, Cognito, User Pool vs Identity pool concepts clear in a big way.</p><h3>References</h3><p><a href="https://aws-amplify.github.io/docs/js/authentication">AWS Amplify Authentication Docs</a></p><p><a href="https://nativebase.io/">NativeBase</a> − cross-platform UI components for React Native &amp; Vue Native</p><p><a href="https://reactnavigation.org/">React Navigation</a> − routing and navigation for your React Native apps</p><p><a href="https://github.com/react-native-community/react-native-google-signin">React-Native Google SignIn</a></p><p><a href="https://serverless.com/">Serverless Framework Toolkit</a> − a toolkit for building Serverless applications easily and fast with any provider</p><p><a href="https://github.com/vhpoet/react-native-styling-cheat-sheet">React-native styling cheat sheet</a></p><h3>Useful Resources</h3><p><a href="https://blog.elao.com/en/dev/from-react-native-init-to-app-stores-real-quick/">From react-native init to app stores real quick</a></p><p><a href="https://www.jamestharpe.com/serverless-typescript-getting-started/">Serverless with Typescript</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3vl6tMEyps7XwjFgsj%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3vl6tMEyps7XwjFgsj%2Fsource.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F3vl6tMEyps7XwjFgsj%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5e1c62b286269181a933068e712fac8/href">https://medium.com/media/e5e1c62b286269181a933068e712fac8/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b2b2350491d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/credits-references-and-useful-resources-8b2b2350491d">Credits, references and useful resources</a> was originally published in <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">Fullstack with React-Native, AWS Serverless and Google oAuth2 Sign-In</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connect React-Native to Serverless API: AWS Sign-in with Amplify SDK]]></title>
            <link>https://medium.com/fullstack-with-react-native-aws-serverless-and/connect-react-native-to-serverless-api-aws-sign-in-with-amplify-sdk-2dc4420fa851?source=rss----a22852ba80ba---4</link>
            <guid isPermaLink="false">https://medium.com/p/2dc4420fa851</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[redux-thunk]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Bharat Tiwari]]></dc:creator>
            <pubDate>Wed, 06 Feb 2019 06:08:55 GMT</pubDate>
            <atom:updated>2019-02-06T16:03:35.240Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part ɪɪɪ: Connect UI to API │Story 03: Update UserSignIn Component to sign-in to AWS</h4><figure><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and"><img alt="" src="https://cdn-images-1.medium.com/proxy/1*oMNRVTNNfDMCgVOc0LVhhA.png" /></a></figure><p>GIT :<em> </em><a href="https://github.com/jsified-brains/noteWordy-UI">Repo</a><em>| </em><a href="https://github.com/jsified-brains/noteWordy-UI/tree/aws-signin">Feature/Story branch</a><em> | </em><a href="https://github.com/jsified-brains/noteWordy-UI/pull/12">PR</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6bSeAwP6Dky29wmXTv0WWA.png" /></figure><p>In the <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/create-aws-identity-pool-f807d008d26f">previous post</a>, we configured Identity pool in AWS Cognito with OpenID Connect (OIDC) as authentication provider for it. The OIDC has been set to use Google as auth provider with the two client Ids we have for <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/set-up-openid-connect-oidc-provider-in-aws-91d498f3c9f7/#f2fe">iOS</a> and <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/set-up-openid-connect-oidc-provider-in-aws-91d498f3c9f7/#fa59">Android</a>.</p><p>In this article, we would connect to this AWS Cognito Identity pool from our react-native app using <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/amplify-sdk-and-navigation-service-4ada4bb9114">Amplify SDK</a>’s <strong>Auth</strong>.<strong>federatedSignIn </strong>method.</p><h4>Add Identity pool Id and Region to Amplify Config</h4><p>1 . Update <strong>src/config/appConstants.js</strong> to add our Identity Pool’s Id and region: 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cae0a61a5b8d54aed95bce582d7d6293/href">https://medium.com/media/cae0a61a5b8d54aed95bce582d7d6293/href</a></iframe><p>👆line # 10–13: we added AWS Cognito <em>Identity Pool Id</em> and <em>Region</em></p><p>2 . Update src/config/appConfig.js as below :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5c9761af38b194434185da539a45cb1/href">https://medium.com/media/d5c9761af38b194434185da539a45cb1/href</a></iframe><p>👆line # 21–25: We provided our Identity Pool details to Amplify’s configuration. The Auth class of Amplify SDK will use these details to connect to the <em>identity pool</em> and get our user authenticated.</p><p>3 . Next, update the UserSignIn component to take the google sessions’s idToken and pass it on to Amplify’s <strong>Auth</strong>.<strong>federatedSignIn </strong>method that would authenticate/authorize the user for AWS and return AWS user session object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a252883318e401fe6bbc8bbde8c66168/href">https://medium.com/media/a252883318e401fe6bbc8bbde8c66168/href</a></iframe><p>Lets see what updates we’ve made to our UserSignIn component above:</p><blockquote><em>1 . We import </em><em>Auth modules from </em><em>aws-amplify.</em></blockquote><blockquote><em>2 . </em><em>Line # 79-80 : In the </em><strong><em>onSignInPress </em></strong><em>method, after GoogleSignIn returns successfully, we call a local class method </em><em>awsSignIn method, passing it the Google’s Sign-in response.</em></blockquote><blockquote><em>3 .</em><em>Line # 97–115 : </em><em>awsSignIn method: In this method, we grab idToken</em><strong><em>, </em></strong><em>expiration time and user’s email from the Google’s Sign-in response, and pass this to Amplify’s </em><strong><em>Auth</em></strong><em>.</em><strong><em>federatedSignIn </em></strong><em>to sign in to AWS Congnito’s Identity pool.</em></blockquote><blockquote><em>4 .</em><em>Line # 136/149 : If user is already signed-in to his/her google account, we call local class method </em><em>getCurrentUserInfo. In this method we call </em><em>awsSignIn method again to sign in to the identity pool.</em></blockquote><blockquote><em>5 . On successful signing in to first Google and then to AWS Identity pool, we dispatch the </em><strong><em>UserSignIn_onSuccess</em></strong><em> redux action and then navigate to the </em><em>Home screen.</em></blockquote><blockquote><em>6 .</em><em>Line #164 : In the </em><strong><em>signOut</em></strong><em> method, we added </em><em>Auth.signOut method to log out from AWS session as well.</em></blockquote><p>With these changes in the UserSignIn component, below is how the authentication/authorization flow would work:</p><p>a . when a users signs in with his/her Google credentials to our app, we would pass the auth-token from Google to AWS Cognito Identity Pool using the Amplify SDK’s method<strong>Auth</strong>.<strong>federatedSignIn .</strong></p><p>b . Our Identity pool is using OpenID Connection Provider(OIDC) to authenticate the user request.</p><p>c . The OIDC has been configured to use Google Authentication provider URL with the client Ids of our iOS and Android apps.</p><p>d . Thus, the Identity pool would authenticate the request coming from the configured ClientIDs with a valid Google sign-in auth token.</p><p>e . After the request is authenticated, AWS Cognito Identity pool would associate the Authenticated User Role policy that we have configured to allow access to our serverless API. Thus our noteWordy app user should be able to access to the our Serverless API.</p><h4>Update signOut method in AppHeader</h4><p>Also update the signOut method in <strong>AppHeader</strong> component to log out from user’s AWS session as well 👇</p><pre>  /**<br>   * <a href="http://twitter.com/name">@name</a> signOut<br>   */<br>  signOut = async () =&gt; {<br>    try {<br>      <strong>await Auth.signOut();<br>      </strong>await GoogleSignin.revokeAccess();<br>      await GoogleSignin.signOut();<br>    } catch (error) {<br>      // console.error(error);<br>    } finally {<br>      this.props.UserSignIn_logOut({});<br>      this.props.navigation.navigate(&#39;SignIn&#39;);<br>    }<br>  };</pre><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><h3>Moment of truth</h3><p>Alright, now that we got the AWS sign in implemented, let’s see if we can post a word to the db without any 403 Forbidden error that we were <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/connect-addeditword-component-to-redux-fc627aa16665/#e2c6">getting earlier before adding the AWS authentication</a>. Run the app on simulator:</p><p>First let’s check if the Sign-in is working as expected, now that we are calling Amplify’s Auth.federatedSignIn, we should get authenticated by the AWS Identity Pool after Google sign-in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vk6LRcA9w1POU_n5naOSkA.gif" /></figure><p>[[ ⚠️ If you noticed, we see an error thrown in the console at Auth.federatedSignIn -AuthClass - Cannot get the current user because the user pool is missing. Please make sure the Auth module is configured with a valid Cognito User Pool ID. But finally it works as expected. This apparently is <a href="https://github.com/aws-amplify/amplify-js/issues/2603">an issue with Amplify SDK</a>. ]]</p><p>Awesome, User Sign-in seem to be working fine. As can be seen from the console log, we get a success for the UserSignIn_OnSuccess action, which we trigger after Auth.federatedSignIn successfully returns confirming that we successfully authenticated with AWS Identity pool.</p><p>Next, lets see if we can post a word to our database table: 👇</p><pre>$ react-native run-ios</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OrPII1r8Olq7xuqBcCnjvQ.gif" /></figure><p>and on Android:</p><pre>$ react-native run-android</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qbh-mG71EmmymS8L4--MwA.gif" /></figure><p>👏 Excellent!! Our app is now able to access our AWS Serverless API and as we see above, the word is now getting posted to the dynamoDB table 🙌</p><p>In the next post, we would update the Home screen to connect it with API via redux, replace the static list of words that we had so far on the screen with a dynamic list of words fetched from database and add Edit and delete words feature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/create-aws-identity-pool-f807d008d26f"><strong>← </strong></a><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/create-aws-identity-pool-f807d008d26f"><strong>Prev:Identity Pool</strong></a>┈<a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">🏠</a>┈<a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/home-screen-with-data-fetched-from-database-c2c3759effd9"><strong>Next:Home screen with data from DB</strong></a><strong>→</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2dc4420fa851" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/connect-react-native-to-serverless-api-aws-sign-in-with-amplify-sdk-2dc4420fa851">Connect React-Native to Serverless API: AWS Sign-in with Amplify SDK</a> was originally published in <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">Fullstack with React-Native, AWS Serverless and Google oAuth2 Sign-In</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create AWS Identity Pool]]></title>
            <link>https://medium.com/fullstack-with-react-native-aws-serverless-and/create-aws-identity-pool-f807d008d26f?source=rss----a22852ba80ba---4</link>
            <guid isPermaLink="false">https://medium.com/p/f807d008d26f</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[aws-cognito]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[redux-thunk]]></category>
            <dc:creator><![CDATA[Bharat Tiwari]]></dc:creator>
            <pubDate>Tue, 05 Feb 2019 23:05:10 GMT</pubDate>
            <atom:updated>2019-02-06T14:03:21.794Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part ɪɪɪ: Connect UI to API │Story 02 : Create AWS Cognito Identity pool</h4><figure><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and"><img alt="" src="https://cdn-images-1.medium.com/proxy/1*oMNRVTNNfDMCgVOc0LVhhA.png" /></a></figure><p>GIT :<em> </em><a href="https://github.com/jsified-brains/noteWordy-UI">Repo</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nIay_nyGWSd4uOYwZ3bHAA.png" /></figure><p>In the <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/set-up-openid-connect-oidc-provider-in-aws-91d498f3c9f7">previous post</a>, we created an <em>OpenId Connect Provider</em> (OIDC) in AWS for our app adding the Google Client Ids of our iOS and Android apps.<br>In this post, we would create an Identity pool in AWS Cognito for our app and use the OIDC as an Authentication provider for the Identity pool.</p><p>So, let’s get started.</p><h3>Get API Gateway Id and Region</h3><p>Before we go to AWS Cognito to create our Identity pool, let’s first get the Gateway Id of the noteWordy serverless API. We would need this when specifying the access/permission policy for the Authenticated User IAM role.</p><p>The API Gateway ID and region can be obtained from our API’s endpoint URL that was given to us in the output of the serverless deploy command when we <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/api-endpoint-to-delete-a-word-b930f0c549a8/#37dd">deployed the service to AWS</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*gLR0ChLS5ckSWuOf23ZqGA.png" /></figure><p>Alternatively , your serverless API Gateway ID and API Gateway Region can also be obtained from AWS management console.</p><p>Go to AWS management console → <strong>API Gateway </strong>Services and select your API</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tcMwBu-5ncHcnzsaYyO-DQ.png" /></figure><p>Find the API Gateway Id and region at the top of the API resources page. 👆</p><pre>📌 🅝🅞🅣🅔<strong> # 4</strong>:</pre><pre><strong>API-Gateway-Id</strong>: &lt;&lt;your API Gateway Id&gt;&gt;<br><strong>API-Gateway-region</strong>: &lt;&lt;your API Gateway region&gt;&gt;</pre><h3>Creating Cognito Identity Pool</h3><p>From AWS management console and select <strong>Cognito</strong> from the services</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*CXupJNsjYbUx14KQBfGyIw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*GWnsrCU66-2ppfd_j157ZA.png" /></figure><p>Create new Identity pool: 👇<br>‒ Add a name for the Identity pool. <br>‒ In the Authentication Providers section, select OpenId tab<br>‒ In the OpenId tab, you should see the OIDC we created in the <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/set-up-openid-connect-oidc-provider-in-aws-91d498f3c9f7">last post</a>.<br>‒ Select the OIDC <br>‒ Click ‘Create Pool’ button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fx4x0EmKFZQbO8-GrZawJg.png" /></figure><p>In the next screen, AWS would create two roles for the Identity pool ‒ a role for <em>Authenticated</em> users and another for <em>Unauthenticated</em> users. Update the access policy for the Authenticated identity role 👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Czj7kegeOrwmtahHdMJWzw.gif" /></figure><p>Above, we updated policy for Authenticated users to access our API. Below is the json for the policy we updated to👇</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: [<br>        &quot;mobileanalytics:PutEvents&quot;,<br>        &quot;cognito-sync:*&quot;,<br>        &quot;cognito-identity:*&quot;<br>      ],<br>      &quot;Resource&quot;: [<br>        &quot;*&quot;<br>      ]<br>    },<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: [<br>        &quot;execute-api:Invoke&quot;,<br>        &quot;apigateway:DELETE&quot;      <br>      ],<br>      &quot;Resource&quot;: [<br>        &quot;arn:aws:execute-api:API-GATEWAY-REGION:*:API-GATEWAY-ID/*/*/*&quot;<br>      ]<br>    }<br>  ]<br>}</pre><p>Replace the API-GATEWAY-REGION and API-GATEWAY-ID with the ones that we noted down above in 📌 <a href="#ae1e">NOTE # 4</a>.</p><p>With above permission policy, a user authenticated with this role by the Identity pool would have access, to the Cognito Sync, Mobile Analytics and the APIs that we deploy to the API Gateway having the specified Id.</p><p>Click ‘Allow’ button at the bottom of the screen. Next you would probably see the below screen from where you can note down the Identity Pool Id and its region. If you don’t see the below screen, you can click on Edit Identity pool link and get the Identity Pool Id from there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BHhKpPIrNuFFRPGaCfgmWg.png" /></figure><pre>📌 🅝🅞🅣🅔<strong> # 5</strong>:</pre><pre><strong>Identity pool id</strong>: &lt;&lt;your Identity Pool Id&gt;&gt;<br><strong>Identity pool region</strong>: &lt;&lt;your Identity Pool region&gt;&gt;</pre><p>Now that we got our Identity pool set up, let’s move to react-native side in the next post to sign-in to this AWS Identity pool and the 403 error, that we were getting earlier to access API from the UI, should get fixed with this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><p><strong>← </strong><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/set-up-openid-connect-oidc-provider-in-aws-91d498f3c9f7"><strong>Prev:OpenId Connect Provider</strong></a>┈<a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">🏠</a>┈<a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/connect-react-native-to-serverless-api-aws-sign-in-with-amplify-sdk-2dc4420fa851"><strong>Next:AWS Sign-in with Amplify→</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f807d008d26f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/create-aws-identity-pool-f807d008d26f">Create AWS Identity Pool</a> was originally published in <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">Fullstack with React-Native, AWS Serverless and Google oAuth2 Sign-In</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Set up OpenID Connect (OIDC) Provider in AWS]]></title>
            <link>https://medium.com/fullstack-with-react-native-aws-serverless-and/set-up-openid-connect-oidc-provider-in-aws-91d498f3c9f7?source=rss----a22852ba80ba---4</link>
            <guid isPermaLink="false">https://medium.com/p/91d498f3c9f7</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws-cognito]]></category>
            <category><![CDATA[redux-thunk]]></category>
            <dc:creator><![CDATA[Bharat Tiwari]]></dc:creator>
            <pubDate>Tue, 05 Feb 2019 16:52:35 GMT</pubDate>
            <atom:updated>2020-03-22T15:47:24.522Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part ɪɪɪ: Connect UI to API│Story 01: Create OpenId Connect Provider in AWS</h4><figure><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and"><img alt="" src="https://cdn-images-1.medium.com/proxy/1*oMNRVTNNfDMCgVOc0LVhhA.png" /></a></figure><p>GIT :<em> </em><a href="https://github.com/jsified-brains/noteWordy-UI">Repo</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tly95ERLKdv5nnNZg7CPyA.png" /></figure><p>In Part 1 of this series, we developed a serverless API for our app and deployed it to AWS.</p><p>In Part 2, we created UI for our app with react-native, got Google Sign-in implemented and added couple of screens for user to view or add words to his/her vocabulary collection with some static/hardcoded data. Finally we added redux actions to get/post data from words db table using our serverless API. However when we tried to post a word, we got a 403–Forbidden error.</p><p>Now, in this Part-III of the series, we would fix this 403 error by setting up AWS authentication and authorization for the app user to access the API using <a href="https://theiconic.tech/authentication-an-in-depth-look-at-aws-cognito-658336515169"><em>AWS Cognito</em></a> Federated Identities.</p><p>Below is the summary of how authentication and authorization would work:</p><ul><li>User logs in with Google Sign-in. Google authenticates the user credentials and provides an auth token for the user session.</li><li>We would pass the user’s Google Auth token to AWS Federated Identity, that in turn would provide a temporary access token for the user’s AWS session having an Authenticated IAM role. We can set permissions for this Authenticated IAM role to have access to our AWS API Gateway so that the user can access the API.</li></ul><p>Thus, we would first have to create an <em>Identity pool</em> in AWS. Identity pool is something that provides an identity for our app user and assigns it a temp access token to access AWS resources. When creating Identity pool, we have to specify an Authentication Provider for it. There are multiple options available for Authentication Providers, like AWS Cognito User pool, Amazon oAuth, Facebook, Google or Twitter oAuth.</p><p>In our case, we are using Google Sign-in on react-native side, so would have to set up the Identity pool with Google as Identity provider.</p><p>There is a limitation with Google Identity Provider for AWS Identity pool. On the AWS Create Identity pool wizard, under Authentication Providers ➝ Google tab, we can only add one client id.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PMAbWHfo-6mhkugtQYKcUQ.png" /></figure><p>To specify multiple client ids (like in our app’s case, we need to specify client Ids for iOS and Android), instead of using Google as Authentication provider for the Identity pool, we would have to use an <strong>OpenId Connect Provider</strong> where we can specify multiple client ids.</p><p>So, as a first step, lets create an OpenID Connect Provider (OIDC) for our app in our AWS account. But before that, let’s get our iOS and Android client ids.</p><h3>Google Client Ids of iOS and Android platforms</h3><p>Get Google Client Ids of iOS and Android apps we created in Firebase developer console.</p><p><strong>iOS app’s Client id</strong> can be obtained from googleservices-info.plist file that we<a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/register-app-for-google-signin-services-for-ios-platform-8980fddf7016/#4914"> downloaded and added to our react-native’s iOS project</a>👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*OZ8xsQzmwIJhoambEX7qbA.png" /></figure><p><strong>Android app’s Client id</strong> can be obtained from google-services.json file that we <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/google-sign-in-for-react-native-android-7d43df78c082/#58ba">downloaded and added to our react-native’s Android project</a> 👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S87lKwyLEQMgEHrkTFiAfg.png" /></figure><pre>📌 🅝🅞🅣🅔 # 3:</pre><pre>iOS Client Id: &lt;&lt;your iOS Client Id&gt;&gt;<br>Android Client Id: &lt;&lt;your Android Client Id&gt;&gt;</pre><h3>Create OpenID Connect (OIDC) Provider in AWS</h3><p><a href="https://aws.amazon.com/blogs/security/building-an-app-using-amazon-cognito-and-an-openid-connect-identity-provider/">Building an App Using Amazon Cognito and an OpenID Connect Identity Provider | Amazon Web Services</a></p><p>(Follow along this guide as below or see the <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc.html">detailed documentation here</a>)</p><p>1 . Go to IAM from AWS Console</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LK7bkEEAH2Q6CTAxmxZ7og.png" /></figure><p>2 . Select Identity Providers option from the left side navigation pane and then select Create Provider 👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KGL-8yEpLD-Bhj7vh05Uzw.png" /></figure><p>3 . On ‘Configure Provider’ screen, select ‘OpenID Connect’ as ProviderType👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*FYFKyiFSIG-84W-l98ZVwQ.png" /></figure><p>4 . Next, enter &quot;https://accounts.google.com&quot; for Provider URL</p><p>In the <strong>Audience</strong> field, enter the client Id of iOS App that we noted down above in <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/set-up-openid-connect-oidc-provider-in-aws-91d498f3c9f7/#4796">Note # 3</a>. 👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*qROJL0fxoW4YWDDOl3V7Eg.png" /></figure><p>5. Click ‘Next Step’ button</p><p><em>(I got an error here saying invalid Provider URL. I had an extra space after </em><a href="https://accounts.google.com/"><em>https://accounts.google.com</em></a><em> , after removing the space, the Next Step button remained disabled and I had to start over)</em></p><p>6 . At this point, AWS Console would create a <em>Thumbprint</em> for your Identity Provider. If you were creating the OIDC using AWS CLI, you would have to generate the Thumbprint manually and provide it.</p><p>In the next screen, you will be asked to verify the generated thumbprint.</p><p>7 . Click <em>Create</em> button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*qrdwrkYbxYDfDRI1YeR7LA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*BadR-2SX2IMWPzQ4nR7-XQ.png" /></figure><p>Click on the created provider to go to its Summary view and click on ‘<strong><em>Add an Audience’</em></strong> button.</p><p>This time enter Android ClientId that we noted down above in <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/set-up-openid-connect-oidc-provider-in-aws-91d498f3c9f7/#4796">Note # 3</a> and click <strong>Save Changes</strong><em>👇</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*cu8y31Qxv3N7vNUZt9CMTg.png" /></figure><p>We have the OIDC provider created. In the next post, we would start setting up an Identity pool in AWS Cognito service for our application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/connect-addeditword-component-to-redux-fc627aa16665"><strong>← </strong></a><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/connect-addeditword-component-to-redux-fc627aa16665"><strong>Prev:AddEdit Component Connected</strong></a>┈<a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">🏠</a>┈ <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/create-aws-identity-pool-f807d008d26f"><strong>Next: AWS Identity Pool→</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91d498f3c9f7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/set-up-openid-connect-oidc-provider-in-aws-91d498f3c9f7">Set up OpenID Connect (OIDC) Provider in AWS</a> was originally published in <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">Fullstack with React-Native, AWS Serverless and Google oAuth2 Sign-In</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connect AddEditWord component to redux]]></title>
            <link>https://medium.com/fullstack-with-react-native-aws-serverless-and/connect-addeditword-component-to-redux-fc627aa16665?source=rss----a22852ba80ba---4</link>
            <guid isPermaLink="false">https://medium.com/p/fc627aa16665</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[redux-thunk]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Bharat Tiwari]]></dc:creator>
            <pubDate>Tue, 05 Feb 2019 15:39:19 GMT</pubDate>
            <atom:updated>2021-02-28T13:14:52.940Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part ɪɪ: React-Native UI │Story 14 : Connect AddEditWord to redux to use redux store data and actions</h4><figure><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and"><img alt="" src="https://cdn-images-1.medium.com/proxy/1*oMNRVTNNfDMCgVOc0LVhhA.png" /></a></figure><p>GIT :<em> </em><a href="https://github.com/jsified-brains/noteWordy-UI">Repo</a> <em>| </em><a href="https://github.com/jsified-brains/noteWordy-UI/tree/redux-for-words-crud">Feature/Story branch</a><em>| </em><a href="https://github.com/jsified-brains/noteWordy-UI/pull/11">PR</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4KVPNUE10v4aVRZbMYQ07A.png" /></figure><p>In the <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/add-redux-store-actions-and-reducers-for-words-data-427db25fa05f">previous post</a>, we defined redux actions and reducer that we would need for CRUD operations with the word data. <br>In this post, we would update the AddEditWord component to connect to redux store and dispatch the actions required to add or update words data to our database table</p><h4>Connect AddWords component to redux</h4><p>📝 Create a file AddEditWordConnected.js under the folder src/screens/AddEditWord👇:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1acf41cb4ce83b85261183614a6e25c/href">https://medium.com/media/e1acf41cb4ce83b85261183614a6e25c/href</a></iframe><p>With this, the redux actions and state that we’ve mapped using mapStateToProps and mapDispatchToProps, would be available as component props. Note that we have mapped the selectedWord state prop from WordsReducer as wordToEdit prop of the component(line # 8 👆).</p><p>Next, update the AddEditWord component as below to use the redux state properties and dispatch mapped action functions on the respective events 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/384b700563765decb3bd2951b2e4cc4e/href">https://medium.com/media/384b700563765decb3bd2951b2e4cc4e/href</a></iframe><p>👆some changes we made to AddEditWord screen component:</p><blockquote><em>– we got rid of </em><em>showAlert variable from the component state as we are not going to show any alert on submit.<br>We also removed </em><em>error state variable. Instead of this, we would use the </em><em>error var from words reducer that we mapped to component prop </em><em>error in </em><em>mapStateToProps in </em><em>AddEditWordConnected.</em></blockquote><blockquote><em>– we added </em><em>componentWillReceiveProps lifecycle method. Here we call </em><em>toastMessage method to show toast box if error prop has any value.</em></blockquote><blockquote><em>– in </em><em>postWord method, we removed the call to </em><em>showAlert and instead dispatch the appropriate redux action of either </em><em>updateWord or </em><em>addWord</em></blockquote><p>Also, now for AddEditWord component, we will export its connected version instead of the standalone component. Update src/screens/index.js 👇</p><pre>export { default as HomeScreen } from &#39;./Home/Home&#39;;<br>export { default as SignInScreen } from &#39;./SignIn/SignIn&#39;;<br>export { default as <strong>AddEditWordScreen</strong> } from <strong>&#39;./AddEditWord/AddEditWordConnected&#39;;</strong></pre><p>With this, we are finally ready to add a word to our database using the serverless API. Let’s see if it works. <br>Reload the app on the simulator.</p><p>First thing, user sign-in is working as expected. 👇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*fDQdyJy79AD45MNjB7K1LQ.gif" /></figure><p>Ok, the User Sign-in using Google Auth seem to working fine.<br>And, let’s see now if add word to db is working?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*qSetQpwUYc9hd7ySmgNySQ.gif" /></figure><p>⚠️ Oops! we got a <a href="https://en.wikipedia.org/wiki/HTTP_403">403 error</a> when posting the word to db 👆</p><p>This is expected. We haven’t yet authenticated our app user to AWS and if you remember, when setting up the API, we have restricted it’s <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/api-endpoint-to-add-post-a-word-a42e35b49e39/#d499">access to users authenticated with AWS IAM</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FwKc00qp7XTCVhXFJev%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FwKc00qp7XTCVhXFJev%2Fsource.mp4&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FwKc00qp7XTCVhXFJev%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="322" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a5f6a10668afc737f22a22dc997dc9b/href">https://medium.com/media/5a5f6a10668afc737f22a22dc997dc9b/href</a></iframe><p>In the next part, we would see how to authenticate our Google user to AWS and get authorized to access the API with AWS Cognito Identity pool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/add-redux-store-actions-and-reducers-for-words-data-427db25fa05f"><strong>← </strong></a><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/add-redux-store-actions-and-reducers-for-words-data-427db25fa05f"><strong>Prev: Redux for words data</strong></a><strong> </strong>┈<a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">🏠</a>┈ <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/part-iii/home"><strong>Next: Part III</strong></a><strong>→</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc627aa16665" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/connect-addeditword-component-to-redux-fc627aa16665">Connect AddEditWord component to redux</a> was originally published in <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">Fullstack with React-Native, AWS Serverless and Google oAuth2 Sign-In</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add redux store, actions and reducers for words data]]></title>
            <link>https://medium.com/fullstack-with-react-native-aws-serverless-and/add-redux-store-actions-and-reducers-for-words-data-427db25fa05f?source=rss----a22852ba80ba---4</link>
            <guid isPermaLink="false">https://medium.com/p/427db25fa05f</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[redux-thunk]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Bharat Tiwari]]></dc:creator>
            <pubDate>Tue, 05 Feb 2019 04:52:38 GMT</pubDate>
            <atom:updated>2019-02-05T15:41:12.725Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part ɪɪ: React-Native UI │Story 13 : Add redux actions and reducers related to CRUD operations to words table</h4><figure><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and"><img alt="" src="https://cdn-images-1.medium.com/proxy/1*oMNRVTNNfDMCgVOc0LVhhA.png" /></a></figure><p>GIT :<em> </em><a href="https://github.com/jsified-brains/noteWordy-UI">Repo</a> <em>| </em><a href="https://github.com/jsified-brains/noteWordy-UI/tree/redux-for-words-crud">Feature/Story branch</a><em>| </em><a href="https://github.com/jsified-brains/noteWordy-UI/pull/11">PR</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fzpdn4YO2beIxBKF0SPAIA.png" /></figure><p>In the <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/amplify-sdk-and-navigation-service-4ada4bb9114">previous post</a>, we installed and configured <em>Amplify SDK</em> that we would use to make async Ajax calls to our serverless API. We installed <strong>redux-thunk</strong> and created <em>Navigation Service</em> that would allow us to access our app’s top-level navigator from anywhere including redux actions. With this we can now trigger navigation to any screen from redux actions.</p><p>In this post, we would set up the redux store, actions and reducers that we will need to store our words data as app-level state and perform CRUD operations to the words table.</p><h4>Define Action Types constants</h4><p>Let’s begin with defining the constants/enums for the events associated with the CRUD operations to words data.</p><p>Add below to the src\redux\actions\actionType.js file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/111dca3291ae08c119a5bddffd425a1d/href">https://medium.com/media/111dca3291ae08c119a5bddffd425a1d/href</a></iframe><h4>Common function to create action:</h4><p><strong><em>📄</em> </strong>Add a new file: src\redux\actions\createAction.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5da4cd60e1d044f980dca9c24ec3b666/href">https://medium.com/media/5da4cd60e1d044f980dca9c24ec3b666/href</a></iframe><p>👆we added a common createAction function that we would use in our actions files to dispatch actions in our redux-thunk actionCreators.</p><h4>Actions for CRUD operations with words collection</h4><p><strong>📂 </strong>Add a new folder: src\redux\actions<strong>\WordsActions<br>📄 </strong>Add a new file: src\redux\actions<strong>\WordsActions\WordsActions.js</strong>👇</p><p>( URLs of our Serverless API can be obtained from what we <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/api-endpoint-to-delete-a-word-b930f0c549a8/#38f4">noted down here</a>)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40705b9914c19eb56148fdd9bb62beb6/href">https://medium.com/media/40705b9914c19eb56148fdd9bb62beb6/href</a></iframe><p>👆We defined action functions that we would like to dispatch for the various events related to CRUD operations with vocab_words data.</p><p>👉 Note how we are using <strong>NavigationService</strong> that we created above, to navigate to <em>Home</em> screen after the addWord or updateWord action completes. 👉 Also note the use of <strong>API</strong> from Amplify<em> </em>to make http calls to our serverless API.</p><h4>Reducers for words collection</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e3ec09a3ea6c6789d658fec8af43e79/href">https://medium.com/media/3e3ec09a3ea6c6789d658fec8af43e79/href</a></iframe><p>👆reducer function to handle various words actions.</p><h4>Add wordsReducer to the combined/root reducer:</h4><p>📝 Edit the file src/redux/reducers/index.js as below👇:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac6cef291da0b67fbc16ce69ea4360da/href">https://medium.com/media/ac6cef291da0b67fbc16ce69ea4360da/href</a></iframe><p>Alright, so we defined the actions and reducers that we would need for CRUD operations with the word data.</p><p>In the next post, we would update the AddEditWord components to connect to redux store and dispatch the actions required to add or update words data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/amplify-sdk-and-navigation-service-4ada4bb9114"><strong>← </strong></a><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/amplify-sdk-and-navigation-service-4ada4bb9114"><strong>Prev: Amplify SDK</strong></a>┈<a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">🏠</a>┈ <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/connect-addeditword-component-to-redux-fc627aa16665"><strong>Next: AddEditWord component connected→</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=427db25fa05f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/add-redux-store-actions-and-reducers-for-words-data-427db25fa05f">Add redux store, actions and reducers for words data</a> was originally published in <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">Fullstack with React-Native, AWS Serverless and Google oAuth2 Sign-In</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Amplify SDK and Navigation Service]]></title>
            <link>https://medium.com/fullstack-with-react-native-aws-serverless-and/amplify-sdk-and-navigation-service-4ada4bb9114?source=rss----a22852ba80ba---4</link>
            <guid isPermaLink="false">https://medium.com/p/4ada4bb9114</guid>
            <category><![CDATA[redux-thunk]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[aws-amplify]]></category>
            <dc:creator><![CDATA[Bharat Tiwari]]></dc:creator>
            <pubDate>Tue, 05 Feb 2019 04:05:21 GMT</pubDate>
            <atom:updated>2019-02-05T14:38:59.523Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part ɪɪ: React-Native UI │Story 12: Adding Amplify SDK to react-native app and setting up Navigation Service</h4><figure><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and"><img alt="" src="https://cdn-images-1.medium.com/proxy/1*oMNRVTNNfDMCgVOc0LVhhA.png" /></a></figure><p>GIT :<em> </em><a href="https://github.com/jsified-brains/noteWordy-UI">Repo</a> <em>| </em><a href="https://github.com/jsified-brains/noteWordy-UI/tree/redux-for-words-crud">Feature/Story branch</a><em>| </em><a href="https://github.com/jsified-brains/noteWordy-UI/pull/11">PR</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4BJwaNvndsbvT2Vlhjq_WA.png" /></figure><p>In the previous posts, we added components for <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/home-screen-component-with-routing-and-navigation-c0cb824d94a5">Home screen</a> that would show a list of words user has added to his/her vocabulary collection and <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/component-to-add-or-edit-a-word-cf30dec4c4a7">AddEditWord screen</a> from where user can add a new word or edit an existing word.</p><p>However, so far these components are static having no communication to database. Our Home component is showing a static list of few hard-coded words &amp; AddEditWord component is also not really adding the word to the db.</p><p>In this post, we will start with the first step of getting our components use the serverless API to communicate with database i.e setting up the redux actions and reducers for CRUD operations of words data.</p><h3>Install Amplify SDK</h3><p>There are several libraries available to make Ajax http calls to API from react, like <a href="https://github.com/mzabriskie/axios">axios</a> or <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">fetch</a>. <br>We would use the <a href="https://github.com/aws-amplify/amplify-js"><strong>Amplify SDK</strong></a> provided by AWS for making Ajax requests to our serverless API.Amplify allows developers to easily work with AWS resources like Cognito, APIs, S3 etc. In a later post, we would also configure Amplify for AWS Cognito services to authenticate and authorize our http requests.</p><pre>$ yarn add <strong>aws-amplify aws-amplify-react-native</strong></pre><pre>$ react-native link aws-amplify-react-native</pre><p>Next, we have to tell Amplify what AWS resources it should use and the Ids/ARNs or endpoints of those resources to point Amplify to right resources.</p><p>1 . 📂 Create a folder config under src<br>2 . 📝 Create a file AppContants.js, under src/config</p><p>We would store all the IDs/ARNs and any other constants that we may need in our app in AppContants.js. You can have these constants configured based on your development environment also, like a set of constants for qa env and other set for prod.</p><p>For now, we will store our API endpoint URL that we have <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/api-endpoint-to-delete-a-word-b930f0c549a8/#0674">noted down here</a> when we deployed our Serverless API to AWS👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b382906f9439030a78871a18b8bc516b/href">https://medium.com/media/b382906f9439030a78871a18b8bc516b/href</a></iframe><p>3 . 📝 Create a file appConfig.js, under src/config</p><p>In this file, we will define the configurations we need for various services in our app. For now, we would add Google SignIn service and Amplify service configuration 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ad1f7ce0d527003643d3843adcf819f/href">https://medium.com/media/0ad1f7ce0d527003643d3843adcf819f/href</a></iframe><p>👆we added functions to set GoogleConfig and AmplifyConfig that we will call in the UserSignIn component’s constructor to have these services configured at the time of our app’s initial loading before user signs in.</p><p>❗ ️️For GoogleConfig, specifying iOS and Android clientIds is optional in our case, as react-native-google-signin plugin would find those from the googleServies-info.plist/googleServies.json files that we have added to iOS(in xCode) &amp; Android(from Android studio) apps respectively.</p><p>ℹ️ Web Client Id as we noted down <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/register-app-for-google-signin-service-for-android-7d43df78c082#0494">here</a>.<br>⚠️ Why provide webClientId to GoogleSignin configuration on mobile platforms? <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/register-app-for-google-signin-service-for-android-7d43df78c082#a86c">discussed this here</a></p><p>Update the UserSignIn component’s constructor to configure Amplify and Google SignIn services using the above two functions 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb41be92eff6d2d040f15f5fd38398bc/href">https://medium.com/media/eb41be92eff6d2d040f15f5fd38398bc/href</a></iframe><p>👆Line # 5, 13–14 : In UserSignIn constructor, we replaced GoogleSignin.configure() with GoogleConfig(). Additionally we are now also calling AmplifyConfig in the constructor.</p><h3>redux-thunk</h3><p>Now that we are getting ready to make <em>async</em> Ajax requests to the API from the redux actions, we will use <a href="https://github.com/gaearon/redux-thunk">redux-thunk</a> that would allow us to write <em>action creators</em> to help us handle these async actions in redux:</p><pre>$ yarn add <strong>redux-thunk</strong></pre><p>Add redux-thunk as middleware to our redux store. Update src\redux\store\index.js as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/424d7d358fca626456158602fef52aa5/href">https://medium.com/media/424d7d358fca626456158602fef52aa5/href</a></iframe><p>👆we added redux-thunk to the middlewares for our store (line # 8).</p><h3>Creating Navigation Service</h3><p>In some cases, like when a new word has been added by the user, we would like to initiate the navigation from the AddWord screen to the Home screen from the redux action itself after the post word API returns successfully. But we don’t have the navigation prop of react-navigation available in our action functions.</p><p>In such cases, react-navigation provides a way to define a <a href="// https://reactnavigation.org/docs/en/navigating-without-navigation-prop.html#docsNav"><em>navigation service</em></a> that allows us to access its navigate method from anywhere in the app where navigation object is not available as props.</p><p>So lets create NavigationService:<br>📝 Create a file NavigationService.js under src/routes 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0959e71b40c6d59958633be92e112258/href">https://medium.com/media/0959e71b40c6d59958633be92e112258/href</a></iframe><p>Next, we would update the App.js to set a ref for the top level navigator for the above service as below 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cfd9b8a5b2e04fb41fa935a34c80965/href">https://medium.com/media/3cfd9b8a5b2e04fb41fa935a34c80965/href</a></iframe><p>With this, now we should be able to dispatch a navigate action on our top-level navigator from anywhere just by importing this NavigationService and calling its navigate method.</p><p>In the next post, we would set up the redux actions and reducers related to the CRUD operations of words data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/component-to-add-or-edit-a-word-cf30dec4c4a7"><strong>← </strong></a><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/component-to-add-or-edit-a-word-cf30dec4c4a7"><strong>Prev:Add/Edit Word Componen</strong></a><strong>t</strong>┈<a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">🏠</a>┈ <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/add-redux-store-actions-and-reducers-for-words-data-427db25fa05f"><strong>Next:Redux for words→</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ada4bb9114" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/amplify-sdk-and-navigation-service-4ada4bb9114">Amplify SDK and Navigation Service</a> was originally published in <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">Fullstack with React-Native, AWS Serverless and Google oAuth2 Sign-In</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Component to Add or Edit a word]]></title>
            <link>https://medium.com/fullstack-with-react-native-aws-serverless-and/component-to-add-or-edit-a-word-cf30dec4c4a7?source=rss----a22852ba80ba---4</link>
            <guid isPermaLink="false">https://medium.com/p/cf30dec4c4a7</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[redux-thunk]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react-navigation]]></category>
            <dc:creator><![CDATA[Bharat Tiwari]]></dc:creator>
            <pubDate>Tue, 05 Feb 2019 01:11:52 GMT</pubDate>
            <atom:updated>2019-02-05T04:06:27.842Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part ɪɪ: React-Native UI │Story 11: Component to Add or Edit a word to vocabulary collection</h4><figure><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and"><img alt="" src="https://cdn-images-1.medium.com/proxy/1*oMNRVTNNfDMCgVOc0LVhhA.png" /></a></figure><p>GIT :<em> </em><a href="https://github.com/jsified-brains/noteWordy-UI">Repo</a> <em>| </em><a href="https://github.com/jsified-brains/noteWordy-UI/tree/add-a-word-screen">Feature/Story branch</a><em>| </em><a href="https://github.com/jsified-brains/noteWordy-UI/pull/10">PR</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OcFirhSsGzEhAn6FlOEe0g.png" /></figure><p>In the previous few posts of the series, we got the redux setup for our react-native app, got react-navigation working, and connected the UserSignIn component to redux to save logged in user details in redux store that we then use to show user’s profile pic and email in a common header component for the app.</p><p>In this post, we would create ‘<em>Add a word</em>’ screen with a simple form for user to add a word to his/her vocabulary collection. For now, we will keep the form static. We don’t have our app connected with API yet, on click of Submit button we would simply show an alert box for now.</p><p>We would also use this same component to edit/update a word, because when updating a word, we would basically need the same form, only this time the fields would be pre-populated. So let’s name our component as AddEditWord.</p><h3>Screen component to Add or Edit a word</h3><p>1 . 📂 Create a folder AddEditWord under src/screens<br>2 . 📄 Create a file AddEditWord.js, under src/screens/AddEditWord👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a27352db0105881dc6d922979a7238a/href">https://medium.com/media/9a27352db0105881dc6d922979a7238a/href</a></iframe><p>👆 It’s pretty straightforward component code:<br>– In componentDidLoad, we first check if the prop wordToEdit is not empty then it means this component is going to be used for updating an existing word; in this case we initialize the state variables to the respective properties of the wordToEdit object to pre-populate the field elements with the corresponding values. If the prop wordToEdit is empty, then we can assume that the component is going to be used for adding a word.</p><p>– In the render method, we have the form elements with a submit button. The form title and the submit button text is set based on whether the component is used for editing an existing word or to create a new word.</p><p>– On press of submit button, we call a function postWord. First we check if the required fields word and meaning are not blank, else we toast an error message. Here, make a note that we have left the calls to redux dispatch actions commented as to-dos. This is something we would add once we have required redux actions ready and component is connected to redux. For now, we simply display an alert box and then take user back to Home screen.</p><p>3 . 📄 Create a file styles.js, under src/screens/AddEditWord 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de8d006d5c3ad98a269d251bed62fb2a/href">https://medium.com/media/de8d006d5c3ad98a269d251bed62fb2a/href</a></iframe><p>4 . Update index.js under src/screens folder to export the above created screen component 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/657e6147d32e73b6c5d8a07e3157c5d5/href">https://medium.com/media/657e6147d32e73b6c5d8a07e3157c5d5/href</a></iframe><p>5 . Update our app’s StackNavigator to have AddEditWord as a screen 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e2b1b2b1d8371650b426c6708c58751/href">https://medium.com/media/5e2b1b2b1d8371650b426c6708c58751/href</a></iframe><p>👆 line # 8, we added AddEditWord screen to the app’s stack navigator.</p><p>6 . In the AddEditWord component, we are using native-base’s toast component. This component requires the app’s topmost component to be <a href="http://docs.nativebase.io/Components.html#toast-def-headref">wrapped inside </a><a href="http://docs.nativebase.io/Components.html#toast-def-headref">&lt;Root&gt; from native-base</a>.<br>So, update App.js 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bcec7f7cdd29ee8b450992db0b0b36de/href">https://medium.com/media/bcec7f7cdd29ee8b450992db0b0b36de/href</a></iframe><p>👆 line # 11-13, we wrapped our topmost navigation container component AppNavigationContainer inside native-base’s &lt;Root&gt;</p><p>7 . Next, add a FAB button to the Home Screen. On press of this FAB, navigate to Add Word screen. Update src/screens/Home/Home.js as below 👇:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d569e94fa0add350a6c1e60828433a8/href">https://medium.com/media/4d569e94fa0add350a6c1e60828433a8/href</a></iframe><p>👆 line # 29–37 : we added a FAB button, on press of this FAB, we call a local function onFabClick. In onFabClick, we simply navigate to AddWord screen.</p><p>Run the app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*KXhRO72AQVFqdxbQ7uCDXQ.gif" /></figure><p><em>App with </em><em>Add A Word screen on iOS and Android 👆</em></p><p>👏 Perfect, our Add/Edit A Word screen is looking good. Later when we would have the app connected to database using API and displaying real/live data, we would see how the same component could be used to edit a word.</p><p>In the next post, we would start preparing for making http/ajax calls to our serverless API from UI by installing Amplify SDK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/header-component-230c5fe4d956"><strong>← </strong></a><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/header-component-230c5fe4d956"><strong>Prev:Header Component</strong></a><strong> </strong>┈<a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">🏠</a>┈ <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/amplify-sdk-and-navigation-service-4ada4bb9114"><strong>Next:Amplify SDK→</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf30dec4c4a7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/component-to-add-or-edit-a-word-cf30dec4c4a7">Component to Add or Edit a word</a> was originally published in <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">Fullstack with React-Native, AWS Serverless and Google oAuth2 Sign-In</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Header component]]></title>
            <link>https://medium.com/fullstack-with-react-native-aws-serverless-and/header-component-230c5fe4d956?source=rss----a22852ba80ba---4</link>
            <guid isPermaLink="false">https://medium.com/p/230c5fe4d956</guid>
            <category><![CDATA[react-navigation]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[redux-thunk]]></category>
            <dc:creator><![CDATA[Bharat Tiwari]]></dc:creator>
            <pubDate>Mon, 04 Feb 2019 22:04:39 GMT</pubDate>
            <atom:updated>2019-02-05T01:19:28.406Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part ɪɪ: React-Native UI│Story 10: Header component</h4><figure><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and"><img alt="" src="https://cdn-images-1.medium.com/proxy/1*oMNRVTNNfDMCgVOc0LVhhA.png" /></a></figure><p>GIT :<em> </em><a href="https://github.com/jsified-brains/noteWordy-UI">Repo</a> <em>| </em><a href="https://github.com/jsified-brains/noteWordy-UI/tree/header-component">Feature/Story branch</a><em>| </em><a href="https://github.com/jsified-brains/noteWordy-UI/pull/7">PR</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wb_oNSh_s5_qykgOkgYplg.png" /></figure><p>In the <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/adding-redux-to-react-native-app-aae93bf287db">previous post</a>, we introduced redux to our react-native app and got the UserSignIn component connected with redux store/state and action dispatchers.</p><h4>Header component</h4><p>Now let’s add a header component for our app where we would show the title of the currently active screen on app, along with a user icon/profile picture along with a <em>logout</em> button on the header. We should be able to add this header from any screen component, so we will keep its Title as an input prop.</p><p>We would connect this header component to redux to have the googleUser from redux store and GoogleSignIn_logOut dispatch action.</p><p>1 . 📂 add a folder <strong>AppHeader</strong> under src/components.</p><p>2 . 📃 add a file <strong>AppHeader.styles.js</strong> 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ad36fc1ce240a04a5cefa14174902e1/href">https://medium.com/media/4ad36fc1ce240a04a5cefa14174902e1/href</a></iframe><p>Above, we defined styles for the elements we would use in the AppHeader component</p><p>3 . 📃 add a file AppHeader.js under src/components/AppHeader 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63beba350843b96d67e0ef3d6fb71bd3/href">https://medium.com/media/63beba350843b96d67e0ef3d6fb71bd3/href</a></iframe><p>Lets see what we are doing in this component 👆</p><ul><li>line #9 — 30 : render() method - renders header, which has user’s profile photo on the left side, a title and user’s email as subtitle in the center and a logout button on the right side. <br>Note, on line# 14 and 20, we are using this.props.googleUser, which would map to redux store’s googleUser state variable once we connect this component to redux.`</li><li>line #35–45 : signOut() method which is called onPress of logout button. It calls react-native-google-signin plugin’s revokeAccess and signOut to log out the user. It then calls <strong>this.props.GoogleSignIn_logOut</strong>,<strong> </strong>which would map to redux dispatch action GoogleSignIn_logOut to reset the googleUser in redux store back to null.</li><li>line #50–54 : we subscribe to didFocus event of react-navigation so that whenever this component is focused(loaded), we would check if this.props.googleUser is not empty, i.e. user has authenticated, else it would send the user back to SignIn screen</li><li>line 61-65: component’s propTypes</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><p>4 . 📃 add a file AppHeaderConnected.js 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6b032c2c50e3a37324d2e3b9f76cf9e/href">https://medium.com/media/d6b032c2c50e3a37324d2e3b9f76cf9e/href</a></iframe><p>👆above we mapped the googleUser state property from redux store and GoogleSignIn_logOut redux dispatch action, to component props and connected the AppHeader component to redux.</p><p>Now that we got all the parts of our app — components, redux and router navigation, hooked together, let’s tests if it’s working as expected. App would first take user to signIn screen, after user successfully signs in, it would take the user to Home screen, where we should see user’s profile photo (or user’s first name initial which google defaults to for user’s photo if user hasn’t provided any picture), with a log out button on the screen header. Restart or reload the app on the simulator: 👇</p><p>5 . Add AppHeader in src/components/index.js 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23c4cd1c6596a05e9478f07ca1d4c029/href">https://medium.com/media/23c4cd1c6596a05e9478f07ca1d4c029/href</a></iframe><p>6 . Add AppHeader component to Home screen component: 👇</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1a7488f3fa441396882f00b106c95db/href">https://medium.com/media/c1a7488f3fa441396882f00b106c95db/href</a></iframe><p>👆 Line # 5 and 13 : we added the AppHeader component to the Home screen passing it the two props title and navigation.<br>We removed the logout button from Home screen as we have it in AppHeader now.<br>(Note that we also moved styles from Home.js to a new file Home.styles.js)</p><p>Now, check the App on simulator. It should refresh by itself if you had the Hot reloading enabled, else reload it manually from the react-native developer menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*vb4wEsHdJMs_eGfnOUz3xA.gif" /></figure><p>Awesome!!! we now have the header component for our app, showing user’s profile pic and email along with a logout button.</p><p>Next, we would create ‘Add a word’ screen with a simple form for user to add a word to his/her vocabulary collection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/adding-redux-to-react-native-app-aae93bf287db"><strong>← </strong></a><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/adding-redux-to-react-native-app-aae93bf287db"><strong>Prev:Adding Redux</strong></a>┈<a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">🏠</a>┈ <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/component-to-add-or-edit-a-word-cf30dec4c4a7"><strong>Next:&#39;Add a Word&#39; screen→</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*cLEpXWbFcO3X0BnYozSLFg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=230c5fe4d956" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fullstack-with-react-native-aws-serverless-and/header-component-230c5fe4d956">Header component</a> was originally published in <a href="https://medium.com/fullstack-with-react-native-aws-serverless-and">Fullstack with React-Native, AWS Serverless and Google oAuth2 Sign-In</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>