{"id":13532645,"url":"https://github.com/dabit3/appsync-react-native-with-user-authorization","last_synced_at":"2025-11-17T15:09:58.772Z","repository":{"id":73190369,"uuid":"127811616","full_name":"dabit3/appsync-react-native-with-user-authorization","owner":"dabit3","description":"End to end React Native + AWS AppSync GraphQL application with queries, mutations, subscriptions, \u0026 user authentication \u0026 authorization","archived":false,"fork":false,"pushed_at":"2018-11-21T00:13:21.000Z","size":166,"stargazers_count":48,"open_issues_count":1,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-21T19:37:13.249Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dabit3.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-02T20:57:03.000Z","updated_at":"2024-06-26T19:08:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"fa3e7bd1-f5a3-4376-8f2a-505edb0f7ca6","html_url":"https://github.com/dabit3/appsync-react-native-with-user-authorization","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dabit3/appsync-react-native-with-user-authorization","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabit3%2Fappsync-react-native-with-user-authorization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabit3%2Fappsync-react-native-with-user-authorization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabit3%2Fappsync-react-native-with-user-authorization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabit3%2Fappsync-react-native-with-user-authorization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dabit3","download_url":"https://codeload.github.com/dabit3/appsync-react-native-with-user-authorization/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabit3%2Fappsync-react-native-with-user-authorization/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284903574,"owners_count":27082075,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-17T02:00:06.431Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T07:01:12.550Z","updated_at":"2025-11-17T15:09:58.742Z","avatar_url":"https://github.com/dabit3.png","language":"JavaScript","funding_links":[],"categories":["Example Projects"],"sub_categories":["Other blogs \u0026 tutorials"],"readme":"# AppSync with User Authorization\n\nA small demo of how to get up and running with AWS AppSync and real world authorization\n\n## User Authentication Setup    \n\nThis step will set up some basic 2 factor user authentication with the current project structure.\n\nIf you would like to set up your own user authentation mechanism this would also work, you would just need to update some logic in SignUp.js \u0026 SignIn.js.\n\n1. Install Amplify CLI   \n\n```bash\nnpm i -g @aws-amplify/cli\n```\n\n2. Configure Amplify CLI    \n\n```bash\namplify configure\n```\n\n3. Create new AWS Amplify Project    \n\n```bash\namplify init\n```\n\n4. Add user signin to project    \n\n```\namplify add auth\n```\n\n5. Push updated configuration to the API    \n\n```\namplify push\n```\n\n\n## AppSync Configuration\n\n1. Create new AppSync App\n\nVisit the [AppSync](https://console.aws.amazon.com/appsync/home) console, click \"Create API\"    \n\n2. Change Authorization Type to \"Amazon Cognito User Pool\". Choose User Pool created in first series of steps. Set \"Default action\" as \"Allow\"    \n\n![](https://imgur.com/awVuhCV.png)    \n\n3. Create the following Schema:    \n\n```graphql\ntype City {\n  id: ID\n  name: String!\n  country: String\n}\n\ntype Query {\n  fetchCity(id: ID): City\n}\n```\n\n4. Click \"Create Resources\"    \n\n5. Click \"Data Sources\" in the left menu, click on the table name under \"Resource\"    \n\n![](https://imgur.com/NtqKi1w.png)    \n\n6. Create an index of \"author\"    \n\n![](https://i.imgur.com/AB4WllW.png)\n\n7. Update \"CreateCity\" request mapping template to the following:\n\n```js\n#set($attribs = $util.dynamodb.toMapValues($ctx.args.input))\n#set($attribs.author = $util.dynamodb.toDynamoDB($ctx.identity.username))\n{\n  \"version\": \"2017-02-28\",\n  \"operation\": \"PutItem\",\n  \"key\": {\n    \"id\": $util.dynamodb.toDynamoDBJson($ctx.args.input.id),\n  },\n  \"attributeValues\": $util.toJson($attribs),\n  \"condition\": {\n    \"expression\": \"attribute_not_exists(#id)\",\n    \"expressionNames\": {\n      \"#id\": \"id\",\n    },\n  },\n}\n```\n\n8. Update the \"ListCities\" request mapping template to the following:\n\n```js\n{\n  \"version\": \"2017-02-28\",\n  \"operation\": \"Query\",\n  \"query\": {\n  \t\"expression\": \"author = :author\",\n    \"expressionValues\": {\n      \":author\": { \"S\": \"${ctx.identity.username}\" }\n    }\n  },\n  \"index\": \"author-index\",\n  \"limit\": $util.defaultIfNull($ctx.args.first, 20),\n  \"nextToken\": $util.toJson($util.defaultIfNullOrEmpty($ctx.args.after, null)),\n}\n```\n\n9. Run project\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdabit3%2Fappsync-react-native-with-user-authorization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdabit3%2Fappsync-react-native-with-user-authorization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdabit3%2Fappsync-react-native-with-user-authorization/lists"}