Closed kuhlaid closed 3 years ago
I found that if I replace the /api/user script with the following I no longer receive errors:
import nc from 'next-connect';
import { all } from '@/middlewares/index';
const handler = nc();
handler.use(all);
handler.get(async (req, res) => {
// Filter out password
const { password, ...u } = req.user;
if (u) res.status(200).json({ user: u });
else res.status(400).json({error: "no user found" });
});
export default handler;
Of course I gutted the script so that isn't saying much. I commented out the Cloudinary config code below as well as the handler.patch function and the errors on the /api/user went away. I will now say that I am not using Cloudinary, so I simply set CLOUDINARY_URL="" in my environment thinking the app would simply ignore any Cloudinary code.
const {
hostname: cloud_name,
username: api_key,
password: api_secret,
} = new URL(process.env.CLOUDINARY_URL);
cloudinary.config({
cloud_name,
api_key,
api_secret,
});
If I simply replace 'new URL(process.env.CLOUDINARY_URL)' with an empty object then API works without the errors.
const {
hostname: cloud_name,
username: api_key,
password: api_secret,
} = {}
With that said, it seems if the process.env.CLOUDINARY_URL value is an invalid or empty string then this API will throw errors. I'm not sure how you 'validate' the URL before using it in the Cloudinary config (and if it fails to replace the config with an empty object), but it would seem like a good idea if it is possible.
If the error is 500, there should be a message to check for in that request in the dev tools. Also for the Cloudinary env, perhaps I can refactor the image functionality so we can plug in whatever service we want.
Sorry for the late reply.
This should be fixed in the latest version, possible due to express-session incompatibility. I confirmed that it did not happen anymore. If it is not the case, feel free to reopen.
The app appears to work fine when running locally. I am able to sign in, sign up, and submit posts. The posts load. However in the browser console there are calls to /api/user that fail with error 500 every few seconds. I can't tell what is calling it. I'm assuming SWR or next-auth, but again I can't tell what is triggering it or how to correct it. The api calls to users is working fine, but if I call /api/user I get the 500 error code.
Does anyone else see this?