now sending userid on login and register
This commit is contained in:
parent
0b32306f84
commit
69c2255614
|
@ -15,10 +15,10 @@ class UserController {
|
||||||
async register(req, res) {
|
async register(req, res) {
|
||||||
const { username, password } = req.body;
|
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`);
|
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) {
|
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);
|
if (!bcrypt.compareSync(password, user.password)) throw new customError(`Wrong user password`, responseCodes.responses.passwords.invalid);
|
||||||
|
|
||||||
const token = jwtutils.genToken(user);
|
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) {
|
async synchronize(req, res) {
|
||||||
|
|
|
@ -6,9 +6,11 @@ import errorHandler from '../utils/pgerrorhandler.js';
|
||||||
|
|
||||||
class UserService {
|
class UserService {
|
||||||
async create(username, password) {
|
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");
|
errorHandler(e, "user");
|
||||||
})
|
})).rows[0].id
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
async getByUsername(username) {
|
async getByUsername(username) {
|
||||||
|
|
Loading…
Reference in New Issue