#✅ - Amplify Getting Started Tutorial doesn't work

15 messages · Page 1 of 1 (latest)

tranquil parrot
#

Something is broken with the Amplify Getting Started Nextjs tutorial found here: https://docs.amplify.aws/start/q/integration/next/ and I'm hoping to get some advise.

The problem occurs in the section called "API with Server-Side Rendering (SSR) where you are asked to copy in two sections of code into pages/_app.js and pages/index.js.

Incidentally, in order for this code to even be used, the tutorial skips an important point during the

npx create-next-app next-amplified

Step. Here it's important to answer "No" to the " Would you like to use TypeScript with this project? … No / Yes" prompt, that otherwise defaults to "Yes". Since the tutorial instructs the audience to insert javascript for these two pieces of code mentioned above, then "No" is the correct response here. Otherwise the default next welcome screen written in typescript will continue to be displayed.

At any rate, after inserting the code (one import added to _app.js, and the entire index.js file replaced), running

npm run dev

and hitting the url http://localhost:3000 with your browser.

The following error is displayed in the browser:

Server Error

Error: No current user
This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
GraphQLAPIClass.<anonymous>
file:/home/chris/projects/amplify/amplify-nextjs-app/next-amplified/node_modules/@aws-amplify/api-graphql/lib/GraphQLAPI.js (243:31)
step
<home>/projects/amplify/amplify-nextjs-app/next-amplified/node_modules/@aws-amplify/api-graphql/lib/GraphQLAPI.js (44:23)
Object.throw
file:/home/chris/projects/amplify/amplify-nextjs-app/next-amplified/node_modules/@aws-amplify/api-graphql/lib/GraphQLAPI.js (25:53)
rejected
<home>/amplify/amplify-nextjs-app/next-amplified/node_modules/@aws-amplify/api-graphql/lib/GraphQLAPI.js (complete text in attached error log).

The console window in which the npm command is run shows a similar error:
Thank you very much for any advice you may have.

tranquil parrot
manic latch
#

I had the same frustrations when running through it and experienced other errors tied to the pages/[id].js too. So while you can just check the code example for differences (or just copy and paste it in to replace what you've got)... it might be best to start from the beginning one more time to ensure there's not dependency issues or other problems.

#

One last note... when you get the "Deploy and host app" step, you might notice a build failure on the Frontend in the Amplify Hosting console.

This is tied to a known issue with Next.JS and Amplify hosting that we're currently working on. However, everything will run locally with npm run dev and you shouldn't see any errors besides the hosting issue.

Let me know if you spot anything wrong in the guide after running through it again or encounter any new errors.

steady vapor
#

So nextjs hosting does not work basically at this time?

tranquil parrot
#

Fantastic! Thank you so much for the message. I'm going to give it a whirl from scratch and I'll post my results to this thread.

left dragonBOT
#

✅ - Amplify Getting Started Tutorial doesn't work

#

Marked as solved.

tranquil parrot
#

I tried out the latest update and it works great.

  1. Following is the TODO schema

This "input" configures a global authorization rule to enable public access to

all models in this schema. Learn more about authorization rules here: https://docs.amplify.aws/cli/graphql/authorization-rules

input AMPLIFY { globalAuthRule: AuthRule = { allow: public } } # FOR TESTING ONLY!

type Todo @model {
id: ID!
name: String!
description: String
}

Doc unclear as to correct GraphQL (should the entire file be replaced or just the model portion leaving the input AMPLIFY line.

  1. Tutorial says to try running amplify console api command. This always will show the following.
    Error: Request failed with status code 401

  2. When running npm run dev, console window generates the following error, that previously would appear in browser window. The browser no longer shows this error however the terminal window does.

Error: No current user
at GraphQLAPIClass.<anonymous> (/home/chris/projects/amplify/amplify-nextjs-app/next-amplified/node_modules/@aws-amplify/api-graphql/lib/GraphQLAPI.js:243:31)
at step (/home/chris/projects/amplify/amplify-nextjs-app/next-amplified/node_modules/@aws-amplify/api-graphql/lib/GraphQLAPI.js:44:23)
at Object.throw (/home/chris/projects/amplify/amplify-nextjs-app/next-amplified/node_modules/@aws-amplify/api-graphql/lib/GraphQLAPI.js:25:53)
at rejected (/home/chris/projects/amplify/amplify-nextjs-app/next-amplified/node_modules/@aws-amplify/api-graphql/lib/GraphQLAPI.js:17:65)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)

the application ran without the error showing up in browser.

left dragonBOT
#

﹖ - Amplify Getting Started Tutorial doesn't work

#

Thread has been re-opened.

low holly
#

Access to every model is denied by default, which is why we add the global public auth rule when we generate the schema.graphql file. It grants public access to a model via an API_KEY so that you don't have to add { allow: public } to every model while you're just getting started and testing.

You can still specify your own @auth rules on each model to try other rules like private, owner, group, iam, etc.

left dragonBOT
#

✅ - Amplify Getting Started Tutorial doesn't work

#

Answer selected!
```👋 Hello @tranquil parrot! The Next.JS Getting Started guide just got an update today because of this exact issue. You can try following it from the start again if you'd like, but the main changes that should fix/impact the No current user error you're seeing would be in the pages/index.js here:

https://docs.amplify.aws/start/getting-started/data-model/q/integration/next/#api-with-server-side-rendering-ssr:~:text=Open pages/index.js and replace it with the following code%3A```
Kudos to @manic latch!
#1039944161723437187 message