added function to the login

This commit is contained in:
Kai Ritthaler 2025-06-18 15:48:53 +02:00 committed by Rudi Regentonne
parent 897e8dbed9
commit c32e345d3d
8 changed files with 292 additions and 174 deletions

View file

@ -4,10 +4,6 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"@prisma/client": "^6.9.0",
"@types/bcryptjs": "^3.0.0",
"@types/multer": "^1.4.12",
"@types/readline-sync": "^1.4.8",
"bcryptjs": "^3.0.2",
"cors": "^2.8.5",
"dotenv": "^16.5.0",
@ -23,9 +19,14 @@
"zod": "^3.24.4"
},
"devDependencies": {
"@prisma/client": "^6.9.0",
"@types/bcryptjs": "^3.0.0",
"@types/cors": "^2.8.19",
"@types/express": "^5.0.1",
"@types/jsonwebtoken": "^9.0.9",
"@types/multer": "^1.4.12",
"@types/node": "^22.15.2",
"@types/readline-sync": "^1.4.8",
"@types/swagger-jsdoc": "^6.0.4",
"@types/swagger-ui-express": "^4.1.8",
"nodemon": "^3.1.10",

View file

@ -11,8 +11,10 @@ export function validateData(schema: z.ZodObject<any, any>) {
} catch (error) {
if (error instanceof ZodError) {
const errorMessages = error.errors.map((issue: any) => ({
message: `${issue.path.join(".")} is ${issue.message}`,
}));
path: issue.path.join("."),
message: issue.message,
}));
res
.status(StatusCodes.BAD_REQUEST)
.json({ error: "Invalid data", details: errorMessages });

View file

@ -5,12 +5,21 @@ import userRouter from "./routes/userRoutes";
import postRouter from "./routes/postRoutes";
import { authenticateToken } from "./middleware/authenticateToken";
import bodyParser from "body-parser";
import cors from "cors";
dotenv.config();
const app = express();
const port = 3000;
const port = 3001;
app.use(
cors({
origin: "http://localhost:3000",
credentials: true,
})
);
app.use((req, res, next) => {
res.header("Access-Control-Expose-Headers", "Authorization");
next();
});
// minIO config
export const minioClient = new Client({
endPoint: "localhost", // Replace with your MinIO server URL
@ -34,7 +43,7 @@ const options = {
},
servers: [
{
url: "http://localhost:3000",
url: `http://localhost:${port}`,
},
],
components: {
@ -56,7 +65,6 @@ const options = {
};
const specs = swaggerJSDoc(options);
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(specs));
app.use(bodyParser.json());
app.use("/api/user", userRouter);
app.use("/api/posts", authenticateToken(), postRouter);

View file

@ -159,6 +159,13 @@
dependencies:
"@types/node" "*"
"@types/cors@^2.8.19":
version "2.8.19"
resolved "https://registry.yarnpkg.com/@types/cors/-/cors-2.8.19.tgz#d93ea2673fd8c9f697367f5eeefc2bbfa94f0342"
integrity sha512-mFNylyeyqN93lfe/9CSxOGREz8cpzAhH+E93xJ4xWQf62V8sQ/24reV2nyzUWM6H6Xji+GGHpkbLe7pVoUEskg==
dependencies:
"@types/node" "*"
"@types/express-serve-static-core@^5.0.0":
version "5.0.6"
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-5.0.6.tgz#41fec4ea20e9c7b22f024ab88a95c6bb288f51b8"