Cleanup
This commit is contained in:
parent
aca54e6535
commit
dd52d44cc2
4 changed files with 3 additions and 10 deletions
|
|
@ -1,4 +1,3 @@
|
|||
import EmailValidator from "email-validator";
|
||||
import { Request, Response } from "express";
|
||||
import Users from "../../../models/User";
|
||||
import { LOGGER } from "../../../util/Logger";
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import EmailValidator from "email-validator";
|
||||
import { Request, Response } from "express";
|
||||
import Users from "../../../models/User";
|
||||
import { LOGGER } from "../../../util/Logger";
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Request, Response } from "express";
|
||||
import ValidateEmail from "../../../email/templates/ValidateEmail";
|
||||
import Users from "../../../models/User";
|
||||
import { LOGGER } from "../../../util/Logger";
|
||||
import ValidateEmail from "../../../email/templates/ValidateEmail";
|
||||
|
||||
export default async (req: Request, res: Response) => {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -8,19 +8,14 @@ export default () => {
|
|||
return async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const token = req.header("authorization").replace("Bearer", "").trim();
|
||||
|
||||
if (!token) {
|
||||
return next();
|
||||
}
|
||||
if (!token) return next();
|
||||
|
||||
const { _id, expiresAt } = jwt.verify(
|
||||
token,
|
||||
process.env.JWT_SECRET as string
|
||||
) as { _id: string; expiresAt: string };
|
||||
|
||||
if (moment(moment()).isAfter(expiresAt)) {
|
||||
return next();
|
||||
}
|
||||
if (moment(moment()).isAfter(expiresAt)) return next();
|
||||
|
||||
const user = await Users.findById(_id);
|
||||
req.user = user.isEmailValidated ? user : null;
|
||||
|
|
|
|||
Loading…
Reference in a new issue