make it run

This commit is contained in:
Anika Raemer 2025-09-22 20:46:31 +02:00
parent c17bb05f0a
commit db480a88e0
7 changed files with 54 additions and 1 deletions

View file

@ -0,0 +1,9 @@
{
"version": "1",
"name": "recipe-backend",
"type": "collection",
"ignore": [
"node_modules",
".git"
]
}

View file

@ -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
}

View file

@ -0,0 +1,15 @@
meta {
name: login
type: http
seq: 2
}
post {
url: http://localhost:4000/login
body: none
auth: inherit
}
settings {
encodeUrl: true
}

View file

@ -14,6 +14,7 @@ export class AuthController {
async login(loginRequest : LoginRequestDto): Promise<LoginResponseDto> {
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");
}

View file

@ -12,6 +12,7 @@ export class UserController {
) {}
async createUser(dto: CreateUserRequestDto): Promise<UserDto> {
// @todo make authorized! Create initial user!
// check mandatory fields
if(!dto.userData){
throw new ValidationError("User data is required")

View file

@ -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);

View file

@ -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" });
}
}