But it’s probably going to be this, from the end of your error that you posted:
Uncaught (in promise) AxiosError {message: ‘Request failed with status code 401’, name: ‘AxiosError’, code: ‘ERR_BAD_REQUEST’, config: {…}, request: XMLHttpRequest, …}
So, the issue seems that you are not authorized to make that request - that’s usually what 401 means. Do you have some kind of auth set up? Does it need a cookie or a token or a key?
Have you played around with something like postman to see how to get this endpoint to work?
please i really want you to help me, i don’t know if you still remember me? I am Anthony from lisbon portugal.
We use to communicate through email last time untill i have some issues but i,m back now.
I have an interview with my employer in a week time and i have to get this done before then
i defined the routes in another file and import it into app.js, then used middleware to run it. For example this is what each database route looks like after fetching the data from the database which i did in another file. lOr let me show you all the process once a time here
server.js
require("dotenv").config();
const app = require("./src/app");
const port = process.env.PORT || 4000;
app.get("/", (req, res) => {
res.send("Hello World!");
});
app.listen(port, () => {
console.log(`Server is running on port http://localhost:${port}`);
});
service.js
const db = require("../config/database");
const notificationServices = require("./notification.services");
const { jobReuseQuery } = require("../job reuseable query/job.queries");
const getAllJobs = async () => {
const { rows } = await db.query(
`
SELECT
jobs.*
FROM "jobs"
LEFT JOIN companies ON companies.id = jobs.company_id
GROUP BY jobs.id
`
);
return rows;
};
controller.js
const getAllJobs = async () => {
const { rows } = await db.query(
`
SELECT
jobs.*
FROM "jobs"
LEFT JOIN companies ON companies.id = jobs.company_id
GROUP BY jobs.id
`
);
return rows;
};
I’m not asking you to list your code. I’m asking you to log out what is happening in that endpoint and any middleware to figure out why it isn’t working. I’m not trying to fix your car for you, I’m trying to help you learn how to do it.
yes i thought as much because i have tried it that way and it gives me more error and i know why. The userRoute is a router route that is coming from router.js files and it has the value of user already, it looks like this :
router.post("/users", userController.createUser);
i imported it from router.js file and then used middeware to plugin the route
That is why i sent you the codes to be able to see what i planned and how i used middleware because if there is an error inside the middleware or the server i will get it in postman.
This is what i have been search for a week now to solve