now sending userid on login and register
This commit is contained in:
@@ -15,10 +15,10 @@ class UserController {
|
||||
async register(req, res) {
|
||||
const { username, password } = req.body;
|
||||
|
||||
await UserService.create(username, password);
|
||||
let userId = await UserService.create(username, password);
|
||||
|
||||
log.info(`New user with name ${username} has just registered`);
|
||||
return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok));
|
||||
return res.status(200).send(userId.toString());
|
||||
}
|
||||
|
||||
async login(req, res) {
|
||||
@@ -28,7 +28,7 @@ class UserController {
|
||||
if (!bcrypt.compareSync(password, user.password)) throw new customError(`Wrong user password`, responseCodes.responses.passwords.invalid);
|
||||
|
||||
const token = jwtutils.genToken(user);
|
||||
return res.status(200).send(token);
|
||||
return res.status(200).send({ id: user.id, token: token });
|
||||
}
|
||||
|
||||
async synchronize(req, res) {
|
||||
|
||||
@@ -6,9 +6,11 @@ import errorHandler from '../utils/pgerrorhandler.js';
|
||||
|
||||
class UserService {
|
||||
async create(username, password) {
|
||||
await db.query("INSERT INTO users (username, password) VALUES ($1, $2)", [username, bcrypt.hashSync(password, 12)]).catch((e) => {
|
||||
let result = (await db.query("INSERT INTO users (username, password) VALUES ($1, $2) RETURNING id", [username, bcrypt.hashSync(password, 12)]).catch((e) => {
|
||||
errorHandler(e, "user");
|
||||
})
|
||||
})).rows[0].id
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
async getByUsername(username) {
|
||||
|
||||
Reference in New Issue
Block a user