Skip to content

Commit

Permalink
feat: Set USERNAME as well as USER variable
Browse files Browse the repository at this point in the history
Mac Users weren't able to set USER variable for the project.
  • Loading branch information
towfiqi committed Jan 11, 2023
1 parent 0c8b457 commit b50733d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion database/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Keyword from './models/keyword';
const connection = new Sequelize({
dialect: 'sqlite',
host: '0.0.0.0',
username: process.env.USER,
username: process.env.USERNAME ? process.env.USERNAME : process.env.USER,
password: process.env.PASSWORD,
database: 'sequelize',
dialectModule: sqlite3,
Expand Down
8 changes: 4 additions & 4 deletions pages/api/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ const loginUser = async (req: NextApiRequest, res: NextApiResponse<loginResponse
if (!req.body.username || !req.body.password) {
return res.status(401).json({ error: 'Username Password Missing' });
}

if (req.body.username === process.env.USER
const userName = process.env.USERNAME ? process.env.USERNAME : process.env.USER;
if (req.body.username === userName
&& req.body.password === process.env.PASSWORD && process.env.SECRET) {
const token = jwt.sign({ user: process.env.USER }, process.env.SECRET);
const token = jwt.sign({ user: userName }, process.env.SECRET);
const cookies = new Cookies(req, res);
const expireDate = new Date();
const sessDuration = process.env.SESSION_DURATION;
Expand All @@ -30,7 +30,7 @@ const loginUser = async (req: NextApiRequest, res: NextApiResponse<loginResponse
return res.status(200).json({ success: true, error: null });
}

const error = req.body.username !== process.env.USER ? 'Incorrect Username' : 'Incorrect Password';
const error = req.body.username !== userName ? 'Incorrect Username' : 'Incorrect Password';

return res.status(401).json({ success: false, error });
};

0 comments on commit b50733d

Please sign in to comment.