Skip to content

Commit

Permalink
fix a few bugs
Browse files Browse the repository at this point in the history
- time stamp exp fix
- not bypass by default locally when dev
- add dist
  • Loading branch information
tim-hub committed Jul 19, 2020
1 parent 26adca7 commit 712b7c8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ temp/
/database.sqlite
/database.sqlite.backup*
/test.sqlite.backup*
dist/

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Money Manager Cloud back-end, to handle CRUD and Authentication and keep the compatibility to the Money Manager EX",
"main": "src/server.ts",
"scripts": {
"dev": "cross-env BYPATH_ACCESS_TOKEN=true tsc-watch --onSuccess \"ts-node src/server.ts\"",
"dev": "tsc-watch --onSuccess \"ts-node src/server.ts\"",
"start:dev": "ts-node src/index.ts",
"start": "node dist/server.js",
"start:pm2": "pm2 start dist/server.js -i 4",
Expand Down
19 changes: 10 additions & 9 deletions src/middleware/jwtAuthMiddleWare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ export const authenticateJWT = async (req, res, next) => {
try {
const payload = await verifyAccessToken(token);
if (payload.exp <= new Date().getTime()) {
res.sendStatus(401);
res.send(401).end();
} else {
const user:User = await User.getRepo().findOne(payload.userID);
delete user.password;
req.user = user;
req.userID = payload.userID;
req.email = payload.email;
next();
}
const user:User = await User.getRepo().findOne(payload.userID);
delete user.password;
req.user = user;
req.userID = payload.userID;
req.email = payload.email;
next();
} catch (e) {
res.sendStatus(401);
res.send(401).end();
}
} else {
res.sendStatus(401);
res.send(401).end();
}
}
};
2 changes: 1 addition & 1 deletion src/services/auth/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const signJWT = (userID: number, email?:string, tokenType = TokenType.Access, mi
userID: userID,
email: email,
iat: currentTimeStamp,
exp: currentTimeStamp + 60 * minutes,
exp: currentTimeStamp + 1000 * 60 * minutes,
},
secret,
{
Expand Down
4 changes: 2 additions & 2 deletions src/services/auth/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export const refreshToken = async (req: Request, res: Response) => {
res.status(200).json(body);
}
} catch (e) {
res.sendStatus(401);
res.send(401).end();
}
} else {
res.sendStatus(401);
res.send(401).end();
}
};

Expand Down

0 comments on commit 712b7c8

Please sign in to comment.