Getting 401 error in postman using NextJS in Gitpod - next.js

Thanks for looking at my issue.
I am learning NextJS, and using Gitpod to test my exercise project.
The code I wrote is just a simple API route which works when you type API route in the browser (it returns DATA in JSON as expected).
However when trying to check the API using postman (and Thunder VScode extension), I get 401 error.
I have tested similar code in Codesandbox, and it works fine using postman.
Can you please advise what am I missing?
Thanks,

This code works with browser and postman,
export default function handler(req, res){
res.status(200).json({name: 'John Doe'})
}
Possible solutions:
Change https to http in posman
Delete .next folder + re-run project
Look at your gitpod settings, maybe you have some restrictions based on your profile

Problem solved :) Thanks to Gitpod
Port should have been set to Public

Related

NextAuth works in local but not in production with Vercel deployment?

Most of the answers I look at on Stackoverflow mentioned checking the correct config variables like:
GOOGLE_CLIENT_ID
GOOGLE_CLIENT_SECRET
NEXTAUTH_URL
I made sure that all the values are correct. Same code works perfectly in local, but in production I keep getting callback error.
I also made sure that I used the right callback uri's in Google Console with my domain.
Please find the below screenshots of Vercel Console and Google API Console. What else am I missing here?
enter image description here

How do you get the comments on a user's snippets using the gitlab API?

In the documentation for the gitlab api, it tells you how to get the notes for a snippet in a particular project by doing:
GET /projects/:id/snippets/:snippet_id/notes
However, this does not work for snippets that the user has created that do not belong to a particular project (i.e. those in /dashboard/snippets).
Is there a way to get the comments on these snippets using the gitlab api as well? I could not find anything in the snippets API docs either.
It's not documented, but you can access snippets without a project just by altering the endpoint:
Instead of GET /projects/:id/snippets/:snippet_id/notes try /snippets/:snippet_id/notes. Everything else about interacting with snippets appears to be the same, just the endpoint changes.

NextJs custom server

I've set a custom server from the example but, my question is...
Can the server code access the NextJs code?
I mean, NextJs is built with webpack, therefore packed in its own context, so if I want to initialize something (let's say, database, logging system, etc.) in the server before NextJs has started, and then access it from NextJs... is it possible? I don't see how unless server code and NextJs code are in the same bundle, is it?
Yes, I guess there are some hacks that can be used, like importing files in runtime with __non_webpack_require__... but that seems like a hack (?) and only in one direction.
Any other better option?
If you use SSR in NextJS, you can access to APIs before rendering.
https://nextjs.org/docs/basic-features/data-fetching/get-server-side-props
If you export a function called getServerSideProps (Server-Side Rendering) from a page, Next.js will pre-render this page on each request using the data returned by getServerSideProps.
It fetches your data upon a user requesting your website everytime.
Thatmeans no matter what you build first on your server. Next.js will fetch for it every time. The comment above me sent the correct link. https://nextjs.org/docs/basic-features/data-fetching/get-server-side-props
TO view all data fetching techniques from next.js visit: https://nextjs.org/docs/basic-features/data-fetching/overview
PLease comment back to this to see if this helped, or if we missunderstood the question, so that we can help solve this issue, or if you resolved it. happy coding!

naming "id.jsx" instead of "[id].jsx" for dynamic routing with Next.js

I'm trying to serve my next.js with AWS Lambda as serverless.
and I've encountered trouble about dynamic routing.
My directory is like below that.
pages
-courses
-[id].jsx
-index.jsx
-index.jsx
It works well on my local server.
But on my Real server(AWS Cloudfront), it doesn't support dynamic routing.
The problem is about courses/[id].jsx.
When I entered my website, I can see an error message on the console.
GET https://RANDOM.cloudfront.net/_next/static/RANDOM/pages/courses/[id].js net::ERR_ABORTED 400
So, I changed the name [id].jsx to id.jsx and I built and deploy it.
and it works.
But I'm not sure it is the correct way to solve my problem.
because nextjs says using [] with dynamic routing.
My question is that is my solution naming without [] is proper or no problem?
and If I am wrong how can I fix it?

Trying to connect to Facebook through the API

I am trying to connect to Facebook through the API but it is giving me an error of Type:
FacebookUser is not defined in vb file.
I have tried with namespaces but it is not working.
what should I do?
Make sure FacebookUser.api is inside the handler. If possible to post part of code would be better to identify the issue.

Resources