Skip to content

Commit

Permalink
fix: Fixes broken Login on windows
Browse files Browse the repository at this point in the history
fixes: 77, 80
towfiqi committed Feb 15, 2023
1 parent 3c48d13 commit c406588
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion database/database.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import Keyword from './models/keyword';
const connection = new Sequelize({
dialect: 'sqlite',
host: '0.0.0.0',
username: process.env.USERNAME ? process.env.USERNAME : process.env.USER,
username: process.env.USER_NAME ? process.env.USER_NAME : process.env.USER,
password: process.env.PASSWORD,
database: 'sequelize',
dialectModule: sqlite3,
3 changes: 2 additions & 1 deletion pages/api/login.ts
Original file line number Diff line number Diff line change
@@ -18,7 +18,8 @@ const loginUser = async (req: NextApiRequest, res: NextApiResponse<loginResponse
if (!req.body.username || !req.body.password) {
return res.status(401).json({ error: 'Username Password Missing' });
}
const userName = process.env.USERNAME ? process.env.USERNAME : process.env.USER;
const userName = process.env.USER_NAME ? process.env.USER_NAME : process.env.USER;

if (req.body.username === userName
&& req.body.password === process.env.PASSWORD && process.env.SECRET) {
const token = jwt.sign({ user: userName }, process.env.SECRET);
4 changes: 2 additions & 2 deletions utils/scraper.ts
Original file line number Diff line number Diff line change
@@ -212,7 +212,7 @@ export const retryScrape = async (keywordID: number) : Promise<void> => {

const filePath = `${process.cwd()}/data/failed_queue.json`;
const currentQueueRaw = await readFile(filePath, { encoding: 'utf-8' }).catch((err) => { console.log(err); return '[]'; });
currentQueue = JSON.parse(currentQueueRaw);
currentQueue = currentQueueRaw ? JSON.parse(currentQueueRaw) : [];

if (!currentQueue.includes(keywordID)) {
currentQueue.push(keywordID);
@@ -232,7 +232,7 @@ export const removeFromRetryQueue = async (keywordID: number) : Promise<void> =>

const filePath = `${process.cwd()}/data/failed_queue.json`;
const currentQueueRaw = await readFile(filePath, { encoding: 'utf-8' }).catch((err) => { console.log(err); return '[]'; });
currentQueue = JSON.parse(currentQueueRaw);
currentQueue = currentQueueRaw ? JSON.parse(currentQueueRaw) : [];
currentQueue = currentQueue.filter((item) => item !== keywordID);

await writeFile(filePath, JSON.stringify(currentQueue), { encoding: 'utf-8' }).catch((err) => { console.log(err); return '[]'; });

0 comments on commit c406588

Please sign in to comment.