Skip to content

Commit ab2ce43

Browse files
committed
Change login to use username
1 parent 7f27325 commit ab2ce43

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

services/user/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@
237237
- HTTP Method: `POST`
238238
- Endpoint: http://localhost:3001/auth/login
239239
- Body
240-
- Required: `email` (string), `password` (string)
240+
- Required: `username` (string), `password` (string)
241241

242242
```json
243243
{
244-
"email": "[email protected]",
244+
"username": "sample123",
245245
"password": "SecurePassword"
246246
}
247247
```

services/user/src/controller/auth-controller.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import bcrypt from "bcryptjs";
22
import jwt from "jsonwebtoken";
3-
import { findUserByEmail as _findUserByEmail } from "../model/repository.js";
3+
import { findUserByUsername as _findUserByUsername } from "../model/repository.js";
44
import { formatUserResponse } from "./user-controller.js";
55

66
export async function handleLogin(req, res) {
7-
const { email, password } = req.body;
8-
if (email && password) {
7+
const { username, password } = req.body;
8+
if (username && password) {
99
try {
10-
const user = await _findUserByEmail(email);
10+
const user = await _findUserByUsername(username);
1111
if (!user) {
12-
return res.status(401).json({ message: "Wrong email and/or password" });
12+
return res.status(401).json({ message: "Wrong username and/or password" });
1313
}
1414

1515
const match = await bcrypt.compare(password, user.password);
1616
if (!match) {
17-
return res.status(401).json({ message: "Wrong email and/or password" });
17+
return res.status(401).json({ message: "Wrong username and/or password" });
1818
}
1919

2020
const accessToken = jwt.sign({
@@ -27,7 +27,7 @@ export async function handleLogin(req, res) {
2727
return res.status(500).json({ message: err.message });
2828
}
2929
} else {
30-
return res.status(400).json({ message: "Missing email and/or password" });
30+
return res.status(400).json({ message: "Missing username and/or password" });
3131
}
3232
}
3333

0 commit comments

Comments
 (0)