safak / nextjs-tutorial

369 stars 141 forks source link

Unable to fetch post data in dashboard.jsx #6

Open busuyiomotosho opened 1 year ago

busuyiomotosho commented 1 year ago

I'm having an issue with handleSubmit function in the dashboard.jsx, specifically fetching data from /api/posts. When I try submitting a new blog post, I keep getting error 500 (internal server error) coming from the await fetch("/api/posts", {...}) line. I even downloaded a local zip copy of your finished project and ran it on my computer but got the same error. What could be the issue and how do I fix it?

Looking forward to your response, thank you!

piglitch commented 1 year ago

I have to say I don't have much experience and you may have already tried this solution but have you checked if your credentials and API keys are correct? Also, make sure the keys and secret are not quoted. Check the .env file.

GithubProvider({ clientId: process.env.GITHUB_ID, clientSecret: process.env.GITHUB_SECRET, }), GoogleProvider({ clientId: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, }), ], pages: { error: "/dashboard/login", },

sepehrsylvanus commented 1 year ago

I'm having an issue with handleSubmit function in the dashboard.jsx, specifically fetching data from /api/posts. When I try submitting a new blog post, I keep getting error 500 (internal server error) coming from the await fetch("/api/posts", {...}) line. I even downloaded a local zip copy of your finished project and ran it on my computer but got the same error. What could be the issue and how do I fix it?

Looking forward to your response, thank you!

the issue is because of our Post model have conflict with the POST api name so go to Post model and change it's name to Posts and change it in the API file too

that worked for me