byyoungjin / myblog-next

https://log.byyoung.me
0 stars 1 forks source link

amplify setup #2

Closed byyoungjin closed 3 years ago

byyoungjin commented 3 years ago
byyoungjin commented 3 years ago

complete guide to amplify with next.js

1. init

HYJui-MacBook-Pro:myblog-next hyj$ amplify init
Note: It is recommended to run this command from the root of your app directory
? Enter a name for the project myblognext
? Enter a name for the environment develop
? Choose your default editor: Visual Studio Code
? Choose the type of app that you're building javascript
Please tell us about your project
? What javascript framework are you using react
? Source Directory Path:  src
? Distribution Directory Path: build
? Build Command:  npm run build
? Start Command: npm run start
Using default provider  awscloudformation
? Select the authentication method you want to use: AWS profile

1. add auth

just default setting

HYJui-MacBook-Pro:myblog-next hyj$ amplify add auth
Using service: Cognito, provided by: awscloudformation

 The current configured provider is Amazon Cognito. 

 Do you want to use the default authentication and security configuration? Defau
lt configuration
 Warning: you will not be able to edit these selections. 
 How do you want users to be able to sign in? Username
 Do you want to configure advanced settings? No, I am done.
Successfully added auth resource myblognexta5c09760 locally

2. add API

Q: default authorization type 은 어떤역할을하나 A: API 콜을 할때, 따로 auth 를 설정하지않으면 default 로 설정되는 값인듯하다. API key Amazon Cognito User pool IAM OpenID Connect [amplify doc](https://docs.amplify.aws/lib/graphqlapi/authz/q/platform/js#api-key]

HYJui-MacBook-Pro:myblog-next hyj$ amplify add api
? Please select from one of the below mentioned services: GraphQL
? Provide API name: myblognext
? Choose the default authorization type for the API Amazon Cognito User Pool
Use a Cognito user pool configured as a part of this project.
? Do you want to configure advanced settings for the GraphQL API No, I am done.
? Do you have an annotated GraphQL schema? No
? Choose a schema template: Objects with fine-grained access control (e.g., a pr
oject management app with owner-based authorization)

GraphQL schema compiled successfully.

Edit your schema at /Users/hyj/Documents/Project_mine/myblog/myBlogNext/myblog-next/amplify/backend/api/myblognext/schema.graphql or place .graphql files in a directory at /Users/hyj/Documents/Project_mine/myblog/myBlogNext/myblog-next/amplify/backend/api/myblognext/schema
? Do you want to edit the schema now? No

3. add storage

HYJui-MacBook-Pro:pnuu hyj$ amplify add storage
? Please select from one of the below mentioned services: Content (Images, audio, video, etc.)
? Please provide a friendly name for your resource that will be used to label this category in the project: pnuustorage
? Please provide bucket name: pnuustorage
? Who should have access: Auth and guest users
? What kind of access do you want for Authenticated users? create/update, read, delete
? What kind of access do you want for Guest users? read
? Do you want to add a Lambda Trigger for your S3 Bucket? No

3. amplify push

error 발생 및 해결 https://github.com/HYJ29/myblog-next/issues/2#issuecomment-811726108

byyoungjin commented 3 years ago

topic 1 : api authorization

api 에서 authorization 에대해 알아보자

Q: user identitiy pool 에서 group 은 어떻게 설정되는건가?

byyoungjin commented 3 years ago

topic 2 : api schema structuring

필요한 query 찾기 - data access pattern

  1. userId 로 Posts 찾기
  2. tagId 로 Posts 찾기
  3. userId 와 tagId 로 Posts 찾기
byyoungjin commented 3 years ago

issue 1_ api key auth provider 필요

@auth directive with 'apiKey' provider found, but the project has no API Key authentication provider configured.

아래에 따라서 public 을 사용하려면 api key 를 추가로 설정해줘야한다. 나머지는 cognito userpool 에서 제공한다. image

HYJui-MacBook-Pro:myblog-next hyj$ amplify update api
? Please select from one of the below mentioned services: GraphQL
? Select from the options below Update auth settings
? Choose the default authorization type for the API Amazon Cognito User Pool
Use a Cognito user pool configured as a part of this project.
? Configure additional auth types? Yes
? Choose the additional authorization types you want to configure for the API AP
I key
API key configuration
? Enter a description for the API key: api key for my blog next.js app
? After how many days from now the API key should expire (1-365): 7