Skip to content

Commit b5ffecd

Browse files
author
Alex Patterson
committed
working example using API KEY
1 parent 65f4266 commit b5ffecd

File tree

6 files changed

+6276
-23
lines changed

6 files changed

+6276
-23
lines changed

amplify/backend/api/ccd/schema.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ type Blog
44
@aws_cognito_user_pools
55
@auth(
66
rules: [
7+
{ allow: public, provider: apiKey }
78
{
89
allow: groups
910
groups: ["Admin"]
@@ -29,6 +30,7 @@ type Post
2930
@searchable
3031
@auth(
3132
rules: [
33+
{ allow: public, provider: apiKey }
3234
{
3335
allow: groups
3436
groups: ["Admin"]
@@ -54,6 +56,7 @@ type Post
5456
comment_status: Boolean
5557
ping_status: Boolean
5658
comment_count: Int
59+
post_featured_image: String
5760
blog: Blog @connection(name: "BlogPosts")
5861
comments: [Comment] @connection(name: "PostComments")
5962
category: [Category] @connection(name: "PostCategories")

amplify/backend/backend-config.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,20 @@
3030
"output": {
3131
"authConfig": {
3232
"defaultAuthentication": {
33-
"authenticationType": "AMAZON_COGNITO_USER_POOLS",
34-
"userPoolConfig": {
35-
"userPoolId": "authccdb1bcb9cf"
33+
"authenticationType": "API_KEY",
34+
"apiKeyConfig": {
35+
"apiKeyExpirationDays": 365,
36+
"description": "ccdapikey"
3637
}
3738
},
38-
"additionalAuthenticationProviders": []
39+
"additionalAuthenticationProviders": [
40+
{
41+
"authenticationType": "AMAZON_COGNITO_USER_POOLS",
42+
"userPoolConfig": {
43+
"userPoolId": "authccdb1bcb9cf"
44+
}
45+
}
46+
]
3947
}
4048
},
4149
"dependsOn": [

nextjs/pages/post/[id].tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
import { API } from 'aws-amplify';
2-
import { useRouter } from 'next/router';
3-
import '../../configureAmplify';
1+
import { API } from "aws-amplify";
2+
import { useRouter } from "next/router";
3+
import "../../configureAmplify";
4+
import gql from "graphql-tag";
45

56
const getPost = `
6-
query getPostById($postId: String!) {
7-
getPostById(postId: $postId) {
8-
id title content
7+
query getPost($id: ID!) {
8+
getPost(id: $id) {
9+
id post_title post_content
910
}
1011
}
1112
`;
1213

13-
const listPosts = `
14+
const listPosts = gql`
1415
query listPosts {
1516
listPosts {
16-
id title content
17+
items {
18+
post_title
19+
id
20+
post_content
21+
}
1722
}
1823
}
1924
`;
@@ -26,8 +31,8 @@ export default function Post({ post }) {
2631
return (
2732
<div>
2833
<h1>Post</h1>
29-
<h2>{post.title}</h2>
30-
<h2>{post.content}</h2>
34+
<h2>{post.post_title}</h2>
35+
<h2>{post.post_content}</h2>
3136
</div>
3237
);
3338
}
@@ -36,7 +41,7 @@ export async function getStaticPaths() {
3641
const postData: any = await API.graphql({
3742
query: listPosts,
3843
});
39-
const paths: any = postData.data.listPosts.map((post) => ({
44+
const paths: any = postData.data.listPosts.items.map((post) => ({
4045
params: { id: post.id },
4146
}));
4247
return {
@@ -49,11 +54,12 @@ export async function getStaticProps({ params }) {
4954
const { id } = params;
5055
const postData: any = await API.graphql({
5156
query: getPost,
52-
variables: { postId: id },
57+
variables: { id: id },
5358
});
59+
console.log(postData);
5460
return {
5561
props: {
56-
post: postData.data.getPostById,
62+
post: postData.data.getPost,
5763
},
5864
};
5965
}

nextjs/pages/posts.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import AWSAppSyncClient, { AUTH_TYPE } from "aws-appsync";
88
const listPosts = gql`
99
query listPosts {
1010
listPosts {
11-
id
12-
title
13-
content
11+
items {
12+
post_title
13+
id
14+
post_content
15+
}
1416
}
1517
}
1618
`;
@@ -34,8 +36,8 @@ export default function Posts() {
3436
const postData: any = await client.query({
3537
query: listPosts,
3638
});
37-
38-
setPosts(postData.data.listPosts);
39+
console.log(postData.data.listPosts.items);
40+
setPosts(postData.data.listPosts.items);
3941
}
4042
}, []);
4143

@@ -44,7 +46,7 @@ export default function Posts() {
4446
<h1>Posts</h1>
4547
{posts.map((post) => (
4648
<Link href={`/post/${post.id}`} key={post.id}>
47-
<a>{post.title}</a>
49+
<a>{post.post_title}</a>
4850
</Link>
4951
))}
5052
</div>

nextjs/src/aws-video-exports.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.
2+
3+
const awsvideoconfig = {
4+
"awsInputVideo": "ccdvod-dev-input-xzkln6vc",
5+
"awsOutputVideo": "d3lbx3hw011qkz.cloudfront.net"
6+
};
7+
8+
export default awsvideoconfig;

0 commit comments

Comments
 (0)