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