generated from lucien/api-template
fix: fixed user creation and channel creation
This commit is contained in:
parent
42eb432b58
commit
5d13a51f8e
3 changed files with 19 additions and 1 deletions
|
@ -24,6 +24,13 @@ router.post('/login', async (req, res) => {
|
|||
router.post('/register', async (req, res) => {
|
||||
const { username, password } = req.body;
|
||||
const connection = await getConnection();
|
||||
|
||||
const use = await getUserByUsername(connection, username);
|
||||
if (use[0]) {
|
||||
connection.end();
|
||||
return res.status(401).send({ error: 'Username already exists' });
|
||||
}
|
||||
|
||||
const hash = sha256(password);
|
||||
await addUser(connection, username, hash);
|
||||
connection.end();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue