From db480a88e01cfa5f9e71b7ed35f917b0c2e7efe6 Mon Sep 17 00:00:00 2001 From: Anika Raemer Date: Mon, 22 Sep 2025 20:46:31 +0200 Subject: [PATCH] make it run --- bruno/recipe-backend/bruno.json | 9 +++++++++ bruno/recipe-backend/createUser.bru | 25 +++++++++++++++++++++++++ bruno/recipe-backend/login.bru | 15 +++++++++++++++ src/controllers/AuthController.ts | 3 ++- src/controllers/UserController.ts | 1 + src/endpoints/AuthPoint.ts | 1 + src/utils/encryptionUtils.ts | 1 + 7 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 bruno/recipe-backend/bruno.json create mode 100644 bruno/recipe-backend/createUser.bru create mode 100644 bruno/recipe-backend/login.bru diff --git a/bruno/recipe-backend/bruno.json b/bruno/recipe-backend/bruno.json new file mode 100644 index 0000000..041dcca --- /dev/null +++ b/bruno/recipe-backend/bruno.json @@ -0,0 +1,9 @@ +{ + "version": "1", + "name": "recipe-backend", + "type": "collection", + "ignore": [ + "node_modules", + ".git" + ] +} \ No newline at end of file diff --git a/bruno/recipe-backend/createUser.bru b/bruno/recipe-backend/createUser.bru new file mode 100644 index 0000000..ba92c1d --- /dev/null +++ b/bruno/recipe-backend/createUser.bru @@ -0,0 +1,25 @@ +meta { + name: createUser + type: http + seq: 1 +} + +post { + url: http://localhost:4000/user + body: json + auth: inherit +} + +body:json { + { + "userData": { + "userName": "test", + "email": "test@raemer.net" + }, + "password": "test" + } +} + +settings { + encodeUrl: true +} diff --git a/bruno/recipe-backend/login.bru b/bruno/recipe-backend/login.bru new file mode 100644 index 0000000..1209530 --- /dev/null +++ b/bruno/recipe-backend/login.bru @@ -0,0 +1,15 @@ +meta { + name: login + type: http + seq: 2 +} + +post { + url: http://localhost:4000/login + body: none + auth: inherit +} + +settings { + encodeUrl: true +} diff --git a/src/controllers/AuthController.ts b/src/controllers/AuthController.ts index 064fac6..c6b7049 100644 --- a/src/controllers/AuthController.ts +++ b/src/controllers/AuthController.ts @@ -14,6 +14,7 @@ export class AuthController { async login(loginRequest : LoginRequestDto): Promise { const userName :string|undefined = loginRequest.userName; const password :string|undefined = loginRequest.password; + console.log("user", userName, " is trying to log in with password", password) if (!userName || !password) { throw new ValidationError("Username and password are required"); } @@ -25,7 +26,7 @@ export class AuthController { throw new UnauthorizedError("Invalid username or password"); } // Compare password - const passwordMatches = encrypt.comparepassword(user.password, password); + const passwordMatches = encrypt.comparepassword(password, user.password); if (!passwordMatches) { throw new UnauthorizedError("Invalid username or password"); } diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index 66301d8..1f074c9 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -12,6 +12,7 @@ export class UserController { ) {} async createUser(dto: CreateUserRequestDto): Promise { + // @todo make authorized! Create initial user! // check mandatory fields if(!dto.userData){ throw new ValidationError("User data is required") diff --git a/src/endpoints/AuthPoint.ts b/src/endpoints/AuthPoint.ts index ac1ca93..2134f7c 100644 --- a/src/endpoints/AuthPoint.ts +++ b/src/endpoints/AuthPoint.ts @@ -16,6 +16,7 @@ const mapper = new UserDtoEntityMapper(); const authController = new AuthController(userRepository, mapper); router.post("/login", async (req, res) => { + console.log("login point called") try { const requestDto: LoginRequestDto = req.body; const responseDto = await authController.login(requestDto); diff --git a/src/utils/encryptionUtils.ts b/src/utils/encryptionUtils.ts index 71cde4a..740c2dc 100644 --- a/src/utils/encryptionUtils.ts +++ b/src/utils/encryptionUtils.ts @@ -13,6 +13,7 @@ export class encrypt { } static generateToken(payload: object) { + // @todo currently, we have an error here! return jwt.sign(payload, JWT_SECRET, { expiresIn: "1d" }); } } \ No newline at end of file