generated from lucien/api-template
fix: fixed register page
This commit is contained in:
parent
90a6b6fa63
commit
414be922bc
3 changed files with 19 additions and 17 deletions
|
@ -8,11 +8,11 @@ const router = express.Router();
|
|||
router.post('/login', async (req, res) => {
|
||||
const { username, password } = req.body;
|
||||
const connection = await getConnection();
|
||||
const users = await getUserByUsername(connection, username);
|
||||
const user = await getUserByUsername(connection, username);
|
||||
connection.end();
|
||||
if (users[0]) {
|
||||
if (users[0].password === sha256(password)) {
|
||||
const token = jwt.sign({ id: users[0].id }, process.env.JWT_SECRET, {
|
||||
if (user[0]) {
|
||||
if (user[0].password === sha256(password)) {
|
||||
const token = jwt.sign({ id: user[0].id }, process.env.JWT_SECRET, {
|
||||
expiresIn: 1000 * 60 * 60 * 24 * 7,
|
||||
});
|
||||
return res.send({ token: token });
|
||||
|
@ -25,8 +25,8 @@ router.post('/register', async (req, res) => {
|
|||
const { username, password } = req.body;
|
||||
const connection = await getConnection();
|
||||
|
||||
const use = await getUserByUsername(connection, username);
|
||||
if (use[0]) {
|
||||
const user = await getUserByUsername(connection, username);
|
||||
if (user[0]) {
|
||||
connection.end();
|
||||
return res.status(401).send({ error: 'Username already exists' });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue