microcmsio/microcms-blog

401 Error by following the document

Closed this issue · 5 comments

newt0 commented

Thank you for publishing this great service and OSS called microCMS!

I'm following the documentation, but I'm getting a 401 error.
(Details in the next post)

newt0 commented

What we did

  • Clone the repo
git clone nextjs-microcms-blog
cd git clone nextjs-microcms-blog
  • Set up the own microCMS account
    Create the API as described in the documentation, and add content (two posts for the blog, one for each other).

  • Set node.js'version to stable(v16.4.0)
    nodebrew use stable.

node -v

v16.4.0
(! I guess Nuxt.js may not support node16 series.)

  • Create an .env file in the root directory of your project
API_KEY=584e75ae-affb-4bff-9844-0dae72b388f8 // *I'll reissue it later
SERVICE_ID=msoss
GA_ID=UA-167209295-6
  • Start a local server to check if the project works
    npm run dev.

And then, I got a 401 error like below.

serviceDomain or endpoint may be wrong. Details: Error: fetch API response status: 401
! image

newt0 commented

In my experience, there was another Nuxt project that did not work with a 16 series node, but worked fine after setting it to a 14 series node (Nuxt does not support 16 series nodes?).

I suspected that this time, too, and changed the node version to 14 series, but it still did not work.

By the way, I set up my own microCMS account with the unofficial version transferred to Next.js, and it worked locally, but some of the images are not displayed.

Is this a problem with the microCMS API settings?
By the way, I set up my own microCMS account with the unofficial version transferred to Next.js, and it worked locally.

newt0 commented

Looks like microcms-js-sdk or nuxt-microcms-module has a trouble.

I tried it with your .env settings on my environment and it certainly didn't work.
However, it works fine with the microcms-blog .env settings.

So I think there is probably a difference in the API settings.
I actually looked at the database and looked it up, but I couldn't find any difference.
If I find out something, I will contact you again.

newt0 commented

I solved it!
It wasn't a problem with the API configuration, nor was it Node.js fault.
The reason was that the value of serviceDomain in nuxt.config.js was left as hardcoded.

I also sent a pull request with this fix.